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);
        }
    }
  • 相关阅读:
    欧拉函数、欧拉定理、费马小定理、拓展欧拉定理
    $CF 635 (Div 2)$
    $CF 634 (Div 3)$
    $CF 633 (Div 2)$
    $ACM$ 课第三次作业-搜索
    《信息安全数学基础一》第一章笔记
    接口测试工具与接口测试框架
    【python】基础知识小结
    【mongo】多个字段进行分组查询
    【mongo】去重操作
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14064256.html
Copyright © 2011-2022 走看看