스프링 부트 개념과 활용
4. 스프링 부트 활용
포스팅 참조 정보
GitHub
공부한 내용은 GitHub에 공부용 Organizations에 정리 하고 있습니다
해당 포스팅에 대한 내용의 GitHub 주소
실습 내용이나 자세한 소스코드는 GitHub에 있습니다
포스팅 내용은 간략하게 추린 핵심 내용만 포스팅되어 있습니다
https://github.com/freespringlecture/springboot-concept-uses/tree/chap04-09-03-mvc-viewresolve
freespringlecture/springboot-concept-uses
백기선님의 스프링 부트 개념과 활용 강의 내용 정리. Contribute to freespringlecture/springboot-concept-uses development by creating an account on GitHub.
github.com
해당 포스팅 참고 인프런 강의
https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8/dashboard
스프링 부트 개념과 활용 - 인프런
스프링 부트의 원리 및 여러 기능을 코딩을 통해 쉽게 이해하고 보다 적극적으로 사용할 수 있는 방법을 학습합니다. 중급 프레임워크 및 라이브러리 Spring Spring Boot 온라인 강의
www.inflearn.com
실습 환경
- Java Version: Java 11
- SpringBoot Version: 2.1.2.RELEASE
9. 스프링 웹 MVC 3부: ViewResolve
Web on Servlet Stack
Spring Web MVC is the original web framework built on the Servlet API and has been included in the Spring Framework from the very beginning. The formal name, “Spring Web MVC,” comes from the name of its source module (spring-webmvc), but it is more commonl
docs.spring.io
Accept Header 에 따라 응답이 달라진다
가장 비교하기 좋은 대상은 Accept Header 이지만 Accept Header를 제공하지 않는 경우도 있음
Accept Header가 없는 경우/path?format=pdf
와 같은 형식으로 알 수 있음
- 어떠한 요청이 들어오면 응답을 만들어 낼 수 있는 모든 View를 찾아냄
- View의 타입을 Accept Header랑 비교를 해서 최종적으로 선택을 하고 리턴함
HttpMessageConvertersAutoConfiguration
HTTP MessageConverter는
HttpMessageConvertersAutoConfiguration
으로 적용됨
JSON으로 내보내는 것은 지원하지만 XML로 내보내려는 경우에는 XmlMapper.class 가 classpath에 없으므로 아래의 로직은 Converting 이 안됨
@Test
public void createUser_XML() throws Exception {
String userJson = "{\"username\":\"freelife\", \"password\":\"123\"}";
//요청을 만드는 단계
mockMvc.perform(post("/users/create")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.accept(MediaType.APPLICATION_XML)
.content(userJson))
//응답 확인단계
.andExpect(status().isOk())
.andExpect(xpath("/User/name")
.string("freelife"))
.andExpect(xpath("/User/password")
.string("123"));
}
jackson-dataformat-xml 추가
jackson-dataformat-xml dependency를 추가하면 XML로 내보낼 수 있음
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.8</version>
</dependency>
'개발강의정리 > Spring' 카테고리의 다른 글
[스프링 부트 개념과 활용] 4-9. 스프링 웹 MVC 5부: 웹JAR (0) | 2019.11.09 |
---|---|
[스프링 부트 개념과 활용] 4-9. 스프링 웹 MVC 4부: 정적 리소스 지원 (0) | 2019.11.08 |
[스프링 부트 개념과 활용] 4-9. 스프링 웹 MVC 2부: HttpMessageConverters (0) | 2019.11.06 |
[스프링 부트 개념과 활용] 4-9. 스프링 웹 MVC 1부: 소개 (0) | 2019.11.05 |
[스프링 부트 개념과 활용] 4-8. Spring-Boot-Devtools (0) | 2019.10.31 |
댓글