뷰 외에도 코드 제너레이션, 이메일 템플릿 등에도 사용 가능
스프링 부트가 자동 설정을 지원하는 템플릿 엔진
JSP를 권장하지 않는 이유
Thymeleaf 사용하기
의존성 추가
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<scope>test</scope>
</dependency>
테스트 코드
@RunWith(SpringRunner.class)
@WebMvcTest(SampleController.class)
public class SampleControllerTest {
@Autowired
MockMvc mockMvc;
@Test
public void hello() throws Exception {
// 요청 "/hello"
// 응답
// - 뷰 이름 : hello
// - 모델 name : cmlee
mockMvc.perform(get("/hello"))
.andExpect(status().isOk())
.andExpect(view().name("hello"))
.andExpect(model().attribute("name", "cmlee"))
.andExpect(content().string(containsString("cmlee")));
}
}
컨트롤러