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);
        }
    }
  • 相关阅读:
    UVALive 4660 A+B
    UVALive 4660 A+B
    UVA10474 Where is the Marble?
    UVA10474 Where is the Marble?
    UVA1339 UVALive3213 POJ2159 ZOJ2658 Ancient Cipher【密码】
    hdu_1108 最小公倍数
    hdu_1106 排序
    hdu_1205 吃糖果
    hdu_1201 18岁生日
    hdu_1005 Number Sequence
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14064256.html
Copyright © 2011-2022 走看看