그리고 Building Restful Web Service 사이트에서 튜토리얼을 진행 해준다.
Greeting Class
package com.godcoder.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 Class
package com.godcoder.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));
}
}
MyresetApplication 돌려주고
http://localhost:8080/greeting 로 들어가본다.
http://localhost:8080/greeting?name=User 여기로도 들어가본다.
package com.godcoder.myrest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyrestApplication {
public static void main(String[] args) {
SpringApplication.run(MyrestApplication.class, args);
}
}
<코딩의 신 - Spring Boot으로 웹 출시까지 #1. 환경 설정>
참고: https://www.youtube.com/watch?v=FYkn9KOfkx0&list=PLPtc9qD1979DG675XufGs0-gBeb2mrona&index=1
'Spring > SpringBoot' 카테고리의 다른 글
Spring Boot으로 웹 출시까지 #3. thymeleaf 기본 익히기 (0) | 2022.05.30 |
---|---|
Spring Boot으로 웹출시 - thymeleaf를 이용한 화면 작성 (0) | 2022.05.30 |
DispatcherServlet & ApplicationContext & 응답(Response)하는 방법 (0) | 2022.05.06 |
서블릿 객체의 생명주기 & web.xml (0) | 2022.05.06 |
Tomcat (0) | 2022.05.06 |