728x90 Spring Boot38 Thymeleaf 탬플릿 엔진 JSP 단점 > 서블릿 엔진이 JSP 스펙을 구현하여 최종적인 뷰가 나옴 - 랜더링된 결과를 확인하기 힘듬 > Thymeleaf 를 사용하면 Thymeleaf가 독자적으로 (Servlet Container의 개입 없이) View를 완성하여 랜더링된 결과를 확인하기 쉬움 (웹서버를 안띄워도 mockMVC만으로 test가 가능하다.) 예제) controller @Controller public class SampleController { @GetMapping("/hello") public String hello(Model model){ model.addAttribute("name", "sangguk"); //model > attribute return "hello"; //view name } }.. 2022. 2. 28. Spring 정적 리소스 맵핑 - 기본 리소스 위치 classpath:/static classpath:/public classpath:/resources/ classpath:/META-INF/resource/ > 위 경로에 요청에 해당하는 리소스가 있다면 자동으로 매핑하여 리턴 ex) https://localhost:8080/hello.html 이라는 요청시 /static/hello.html이 있는 경우 해당 리소스를 리턴 * 맵핑설정을 변경하고 싶은 경우 spring.mvc.static-path-pattern=/sangguk/** 이제는 https://localhost:8080/hello.html > https://localhost:8080/sangguk/hello.html 으로 요청해야함 2022. 2. 27. ViewResolver Accept header값에 따라 응답이 달라짐 > 해당하는 view에 맞게 Return xml로 응답을 받고 싶은 경우 > xpath사용 예시 @RunWith(SpringRunner.class) @WebMvcTest(UserController.class) public class UserControllerTest { @Autowired MockMvc mockMvc; @Test public void createUser_XML() throws Exception { String userJson = "{\"username\":\"sangguk\", \"password\":\"1234\"}"; mockMvc.perform(post("/users/create") .contentType(MediaType.APPLIC.. 2022. 2. 27. HttpMediaTypeNotAcceptableException MockHttpServletRequest: HTTP Method = POST Request URI = /users/create Parameters = {} Headers = [Content-Type:"application/json;charset=UTF-8", Accept:"application/xml", Content-Length:"41"] Body = {"username":"sangguk", "password":"1234"} Session Attrs = {} Handler: Type = com.example.springbootwebmvc.user.UserController Method = com.example.springbootwebmvc.user.UserController#create(User) As.. 2022. 2. 27. 이전 1 2 3 4 5 6 7 ··· 10 다음 728x90