MVC(Model View Controller)
웹 어플리케이션을 어플리케이션 서버에 배포하지 않고 테스트용 MVC 환경을 만들어 요청 및 전송, 응답을 제공하는 유틸리티 클래스
mvc.perform(get("/hello"))
.andExcept
- mvc.perform의 결과(status)를 검증
status().isOk
.andExcept(status().isOk)
- perform의 결과가 성공적인지(200,404,500 등)
content().string(~)
.andExcept(content().string(hello))
- mvc.perform의 결과를 검증하는 것으로 응답의 본문의 내용을 검증
- perform 내용중 ~ 값이 있는지 검증
model().attributeExists("article")
.andExpect(model().attributeExists("article"))
- model 의 프로퍼티 중 articles라는 프로퍼티가 있는지 검증
mvc.perform(get("/api/articles"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.valueOf("application/hal+json")));
.andExpect(model().attributeExists("article"));
디펜던시에 하기 코드 추가
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
<?xml version="1.0" ?>
<thlogic>
<attr sel="#header" th:replace="header :: header"></attr>
<attr sel="#footer" th:replace="footer :: footer"></attr>
</thlogic>
anyRequest
모든 리소스를 의미
permitAll
antMatchers 설정한 리소스의 접근을 인증절차 없이 허용한다는 의미
.authorizeRequests().antMatchers("/login**", "/web-resources/**", "/actuator/**").permitAll()
.authorizeRequests(auth -> auth.anyRequest().permitAll())
addObject를 통해 데이터를 저장
addObject(”key”, value), setViewName(” … “)
setViewName을 통해 이동하고자 하는 View페이지를 저장
Model & View 동시에 리턴 가능
ModelAndView mv = new ModelAndView();
return type ModelAndView