。゚(*´□`)゚。

코딩의 즐거움과 도전, 그리고 일상의 소소한 순간들이 어우러진 블로그

강의/Spring

[Spring 입문] 1-2 라이브러리 살펴보기, view 환경설정, 빌드 실행

quarrrter 2023. 8. 7. 23:23

라이브러리 살펴보기

기본으로 엄청 많이 필요함 gradle해보면 몇10메가 나옴

gradle, maven 같은 build tool은 의존관계를 다 관리해줌 

string-boot-starter 하나 땡겨오면 필요한 라이브러리들을 자동으로 다 땡겨옴 

내가 받아온 라이브러리 두 개, 그 밑에 라이브러리들은 자동으로 import (embadded 내장된)

현업자들은 sysout말고 log로 출력해서 확인해야함.... 

요즘에는 logback을 많이 사용함

스프링 부트 라이브러리
spring-boot-starter-web
-spring-boot-starter-tomcat: 톰캣 (웹서버)
-spring-webmvc: 스프링 웹 MVC
spring-boot-starter-thymeleaf: 타임리프 템플릿 엔진(View)
spring-boot-starter(공통): 스프링 부트 + 스프링 코어 + 로깅
-spring-boot
--spring-core
-spring-boot-starter-logging
--logback, slf4j
테스트 라이브러리
spring-boot-starter-test
-junit: 테스트 프레임워크
-mockito: 목 라이브러리
-assertj: 테스트 코드를 좀 더 편하게 작성하게 도와주는 라이브러리
-spring-test: 스프링 통합 테스트 지원

Welcome page 만들기 (도메인으로 들어왔을 때 첫 화면)

src/resources/static/index.html

https://docs.spring.io/spring-boot/docs/current/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

spring.io에서 검색해서 기능 사용 가능 

 

 

https://www.thymeleaf.org/

 

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

 

 

 

<p th ~~>

th: thymeleaf의 th, 타임리프 문법 사용 가능 

 

http:localhost:8080/hello

GetMapping("hello")의 hello가 get 방식으로 넘어오면 hello url에 매칭됨

그럼 정의되어있는 hello 메서드가 실행됨 

다음 model이 넘어오는데 model에 키는 data, 값은 hello!!가 넘어옴

hello를 리턴 (resources의 hello.html) ==>

==>컨트롤러에서 리턴 값으로 문자를 반환하면 뷰리졸버가 화면을 찾아 처리한다. 

resource:templates/{ViewNAme}+.html

 


빌드 후 cmd에서 snapshot.jar 파일 실행하면 intellij에서 run 한 것과 같이 실행 가능 

java -jar hello-spring-0.0.1-SNAPSHOT.jar

 


Intellij auto import 설정 + "ctrl+alt+o"