zoukankan      html  css  js  c++  java
  • [Java spring] Building a command-line application

    pom.xml:

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>

    Implement CommandLineRunner:

    package com.frankmoley.boot.clr.roomclrapp;
    
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.stereotype.Component;
    import org.springframework.web.client.RestTemplate;
    
    import java.util.*;
    
    @Component
    public class RoomCleaningPrimer implements CommandLineRunner {
    
        private RestTemplate restTemplate;
    
        public RoomCleaningPrimer() {
            super();
            this.restTemplate = new RestTemplate();
        }
    
        @Override
        public void run(String... strings) throws Exception {
            String url = "http://localhost:8080/api/rooms";
            Room[] roomArray = this.restTemplate.getForObject(url, Room[].class);
            List<Room> rooms = Arrays.asList(roomArray);
            rooms.forEach(System.out::println);
        }
    }
  • 相关阅读:
    JavaScript寄生组合式继承分析
    常用的css命名规则:
    jshint配置(js检查)
    当页面关闭或刷新时提示用户
    Ionic 开发环境搭建
    VS Code前端开发利器-常用快捷键
    Uploadify 上传插件引起Chrome崩溃解决方法
    “全栈工程师”的尴尬
    redis集群升级,数据迁移及校验
    K-means
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14064256.html
Copyright © 2011-2022 走看看