mvc
-
스프링 웹 MVC - 2 (스프링 부트 활용 - 6)Programming/Spring Boot 2020. 3. 10. 20:10
1. ThymeLeaf 동적으로 컨텐츠를 생성해서 응답으로 보내야 하는 경우 템플릿 엔진을 사용 1) 테스트 생성 @RunWith(SpringRunner.class) @WebMvcTest(SampleController.class) public class SampleControllerTest { @Autowired MockMvc mockMvc; @Test public void hello() throws Exception { mockMvc.perform(get("/hello")) .andExpect(status().isOk()) .andDo(print()) .andExpect(view().name("hello")) .andExpect(model().attribute("name", is("hongchan"))..
-
스프링 웹 MVC - 1 (스프링 부트 활용 - 5)Programming/Spring Boot 2020. 3. 10. 00:44
- 아무런 설정 없이 스프링 웹 MVC를 바로 사용할 수 있는 것은 AutoConfigure 덕분 - WebMvcConfigurer 을 구현하여 스프링 자동 설정에 더해서 여러 설정을 입맛대로 변경 가능 1. HttpMessageConverters - 스프링 프레임워크에서 제공하는 인터페이스 - HTTP 요청 본문 객체로 변경하거나, 객체를 HTTP 응답 본문으로 변경할 때 사용 {"username":hongchan, "password":"123"} User - @RequestBody, @ResponseBody와 함께 쓰임 1) 테스트 코드 작성 @Test public void createUser_JSON() throws Exception { String userJson = "{\"username\":\..