Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 1.46 KB

230410_section2.md

File metadata and controls

80 lines (59 loc) · 1.46 KB

Section 2) 스프링 부트 시작하기

개발환경 준비

SpringBoot 2.7.6 기준 -> JDK 8,11,17(11을 주로 사용)

java -version

curl -s "https://get.sdkman.io" | bash #sdk 매니저

sdk list java
sdk install java 11.0.17-amzn
sdk use java 11.0.17-amzn #프로젝트 별 쓰고 싶은 version(일시적으로) 설정
sdk install springboot 2.7.6 //springboot 다운받아 쓰고 싶다면

프로젝트 생성

  1. Spring Initializr
  1. IDE의 Spring Initializr
  2. Spring Boot CLI
spring init
#shell 들어가서 하려면
spring shell
init
#-d: dependency web,... group -j java version -n name -x folder
init -b 2.7.6 -d web -g tobyspring -j 11 -n helloboot -x helloboot
./gradlew bootRun #잘 만들어 졌는지 체크
exit # shell 나오기
idea .

Hello 컨트롤러

@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello(String name){
        return "Hello "+ name;
    }
}

Hello API 테스트

https://httpie.io/

brew install httpie
http -v ":8080/hello?name=Spring"

HTTP 요청과 응답

GET /hello?name=Spring HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/3.2.1



HTTP/1.1 200
Connection: keep-alive
Content-Length: 12
Content-Type: text/plain;charset=UTF-8
Date: Tue, 11 Apr 2023 01:18:03 GMT
Keep-Alive: timeout=60

Hello Spring