gradle
라이브러리 의존관계springboot starter
를 사용하면 스프링 웹 프로젝트에 필요한 라이브러리를 알아서 가져와 준다.<스프링 부트 라이브러리>
spring-boot-starter-web
spring-boot-starter-tomcat
: 톰캣(웹서버)spring-webmvc
스프링 웹 MVspring-boot-starter-thymeleaf
: 타임리프 템플릿 엔진spring-boot-starter
(공통)spring-boot
(스프링부트)spring-core
(스프링 코어)spring-boot-starter-logging
(로깅)logback
, slf4f
<테스트 라이브러리>
spring-boot-starter-test
junit
: 테스트 프라임워크mockito
: 목 라이브러리asserj
: 테스트 코드 작성 편하게 도와주는 라이브러리spring-test
: 스프링 통합 테스트 지원<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<!-- th (thymeleaf) -->
<p th:text="'안녕하세요, ' + ${data} + '님!'" />
</body>
</html>
viewResolver
로 전달thymeleaf
템플릿 엔진에 넘김thymeleaf
템플릿 엔진이 변환처리한 html을 브라우저에 넘김@GetMapping("hello-mvc")
public String helloMvc(@RequestParam(value = "name", required = false) String name, Model model) {
model.addAttribute("name", name);
return "hello-template"; // 마지막에 view 이름을 리턴
}
@requestBody
는 http의 body에 문자내용 직접 반환
객체 전달 시 HttpMessageConverter
가 동작
기본 문자 : StringHttpMessageConverter
동작
객체 : MappingJackson2HttpMessageConverter
(default)
api 방식에서 객체를 전달할 경우 json 형식으로 변환하여 데이터 전달