기존 mediaType설정이 deprecated되었다.

단순히 for문으로 처리되던 기존 viewResolver 결정 프로세스가 바뀌기를 고대했었는데 이제사 좀더 디테일하게 변경이 가능해졌다.

 

ContentNegotiationStrategy가 추가되었는데 이를 통해

확장자 기준, 헤더값 기준 결정이나 고정된 mediaType리턴과 같은 전략적인 설정이 가능하게 되었다.

 

이에 따라서 기존의 단순한 for문형태의 viewResolver결정 부분을 비슷하게 구현하려면 아래처럼 구현을 해준다.

 

 

  
 

 

ContentNegotiatingViewResolver viewResolver = new ContentNegotiatingViewResolver();

// 확장자 기준 결정

Map<String, MediaType> mediaTypes = new HashMap<String, MediaType>();

mediaTypes.put("html", MediaType.TEXT_HTML);

mediaTypes.put("json", MediaType.APPLICATION_JSON);

ContentNegotiationStrategy pathExtensionContentNegotiationStrategy = new PathExtensionContentNegotiationStrategy(mediaTypes);

// 헤더값 기준 결정

ContentNegotiationStrategy  headerContentNegotiationStrategy = new HeaderContentNegotiationStrategy();

/* order에 따라 우선순위 결정되므로 순서 주의 */

ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager(pathExtensionContentNegotiationStrategy, headerContentNegotiationStrategy);

viewResolver.setContentNegotiationManager(contentNegotiationManager);

 

 
  

 

 

 

참조 http://richardadams606blog.blogspot.kr/2013_01_01_archive.html

 


출처 - http://blog.naver.com/PostView.nhn?blogId=luversof&logNo=50162197798





Posted by linuxism
,