월루를 꿈꾸는 대학생
[SpringBoot 입문] 환경세팅 본문
자바 버전 11
인텔리제이 세팅
기본 세팅
gradle 은 의존관계를 생각함
spring boot starter web
- web만 땡기는게 아니라 web이 필요한 부가적인 의존 패키지들도 같이 땡겨오니까 목록이 많이 보임
밑으로 계속 떙겨 나옴 -> 의존적
나중에 로그 출력할 때
system.out.print 이런거로 남기면 안 됨
로그로 따로 만들어서 써야 나중에 정리도 가능
웰컴 페이지
- resources/static/index.html
- index.html이 8080로 들어갔을 때 나오는 웰컴 페이지가 됨
- 모르는 경우엔 직접 찾아서 확인할 필요도 있다
https://docs.spring.io/spring-boot/docs/2.7.7/reference/html/web.html#web
Web
Graceful shutdown is supported with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and servlet-based web applications. It occurs as part of closing the application context and is performed in the earliest
docs.spring.io
템플릿 엔진
- html 모양을 바꿀 수 있음
- thymeleaf
Thymeleaf
Integrations galore Eclipse, IntelliJ IDEA, Spring, Play, even the up-and-coming Model-View-Controller API for Java EE 8. Write Thymeleaf in your favourite tools, using your favourite web-development framework. Check out our Ecosystem to see more integrati
www.thymeleaf.org
컨트롤러
- 웹 진입시 가장 먼저 만나는 부분
- 클래스에 어노티에이션 controller
@Controller
@GetMapping("hello")
get 방식으로 접근할 때 hello 경로이면 해당 어노티에이션 붙은 메서드가 실행
model.addAttribute("data", "hello");
모델에 속성을 추가함
키 : data
값 : hello
템플릿 파일에서 해당 값들을 모델을 통해서 받고 실행
<p th:text="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p>
data 키 값은 hello임
스프링부트 웹 순서
1. 웹에서 url로 /hello 로 접근
2. 스프링이 컨트롤러 중 매핑 되는게 있나 찾음 /hello 있는 거
3. url 매칭된 컨트롤러의 메서드를 실행
4. 스프링이 모델을 만들고 키랑 값을 넣어줌
5. 뷰리졸버가 return 되는 걸 보고 템플릿에 html 매칭되는 거 있나 찾고 있는 경우 hello.html 에다가 해당 모델을 html로 보냄
6. hello.html은 받은 모델을 기반으로 랜더링 해줌
7. html에 ${} 에 모델에 있는 값들을 넣어서 랜더링
8. 유저에게 전달
devtools 세팅
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compileOnly("org.springframework.boot:spring-boot-devtools")
}

출처
'Programing > Spring Boot' 카테고리의 다른 글
[Spring Boot 입문] 회원 관리 (0) | 2023.01.11 |
---|---|
[Spring Boot 입문] 스프링 웹 개발 기초 (0) | 2023.01.08 |
[Spring Boot] 템플릿 상속 (0) | 2023.01.01 |
[Spring Boot] static 디렉토리 (0) | 2023.01.01 |
[Spring Boot] 서비스 (0) | 2023.01.01 |