상세 컨텐츠

본문 제목

Spring Boot으로 웹 출시까지 #1. 환경 설정

Java/코딩의 신

by Gopythor 2023. 11. 1. 13:42

본문

728x90
반응형

Spring boot의 예시가 바껴 기록용으로 남겨놓음.

 

 

 

Greeting.java

 

package com.example.myrest;


public class Greeting {
    private final long id;
    private final String content;

    public Greeting(long id, String content) {
        this.id = id;
        this.content = content;
    }

    public long getId() {
        return id;
    }
    public String getContent() {
        return content;
    }
}

 

GreetingController.java

package com.example.myrest;


import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @GetMapping("/greeting")
    public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
        return new Greeting(counter.incrementAndGet(), String.format(template, name));
    }
}

https://www.youtube.com/watch?v=FYkn9KOfkx0&t=545s

728x90
반응형

관련글 더보기

댓글 영역