本文整理汇总了Java中org.springframework.web.servlet.view.ContentNegotiatingViewResolver.setContentNegotiationManager方法的典型用法代码示例。如果您正苦于以下问题:Java ContentNegotiatingViewResolver.setContentNegotiationManager方法的具体用法?Java ContentNegotiatingViewResolver.setContentNegotiationManager怎么用?Java ContentNegotiatingViewResolver.setContentNegotiationManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.servlet.view.ContentNegotiatingViewResolver
的用法示例。
在下文中一共展示了ContentNegotiatingViewResolver.setContentNegotiationManager方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: contentNegotiatingViewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ContentNegotiatingViewResolver contentNegotiatingViewResolver() {
List<View> defaultViews = new ArrayList<>(2);
defaultViews.add(jsonCatnapSpringView());
defaultViews.add(jsonpCatnapSpringView());
List<CatnapWrappingView> catnapViews = new ArrayList<>(2);
catnapViews.add(jsonCatnapSpringView());
catnapViews.add(jsonpCatnapSpringView());
CatnapViewResolver catnapViewResolver = new CatnapViewResolver();
catnapViewResolver.setViews(catnapViews);
List<ViewResolver> viewResolvers = new ArrayList<>(1);
viewResolvers.add(catnapViewResolver);
ContentNegotiatingViewResolver cnvr = new ContentNegotiatingViewResolver();
cnvr.setContentNegotiationManager(mvcContentNegotiationManager());
cnvr.setOrder(1);
cnvr.setDefaultViews(defaultViews);
cnvr.setViewResolvers(viewResolvers);
return cnvr;
}
示例2: contentNegotiatingViewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ViewResolver contentNegotiatingViewResolver(
ContentNegotiationManager manager) {
List< ViewResolver > resolvers = new ArrayList<ViewResolver>();
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
viewResolver.setViewClass(TilesView.class);
resolvers.add(viewResolver);
JsonViewResolver r2 = new JsonViewResolver();
resolvers.add(r2);
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setViewResolvers(resolvers);
resolver.setContentNegotiationManager(manager);
return resolver;
}
示例3: contentNegotiatingViewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ViewResolver contentNegotiatingViewResolver(ContentNegotiationManager manager) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(manager);
// Define all possible view resolvers
List<ViewResolver> resolvers = new ArrayList<ViewResolver>();
resolvers.add(excelViewResolver());
resolver.setViewResolvers(resolvers);
return resolver;
}
示例4: cnViewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
/**
* Bean to configure view resolver
*
* @param cnm the content negotion manager
* @return the view resolver
*/
@Bean
public ViewResolver cnViewResolver(final ContentNegotiationManager cnm) {
final ContentNegotiatingViewResolver cnvr =
new ContentNegotiatingViewResolver();
cnvr.setContentNegotiationManager(cnm);
return cnvr;
}
示例5: contentNegotiatingViewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ViewResolver contentNegotiatingViewResolver(
ContentNegotiationManager manager) { // Esse método determina os possiveis formatos de retorno da viewResolver
List<ViewResolver> resolvers = new ArrayList<ViewResolver>();
resolvers.add(internalResourceViewResolver());
resolvers.add(new JsonViewResolver());
resolvers.add(getMarshallingXmlViewResolver());
ContentNegotiatingViewResolver resolver
= new ContentNegotiatingViewResolver();
resolver.setViewResolvers(resolvers);
resolver.setContentNegotiationManager(manager);
return resolver;
}
示例6: testContentNegotiation
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Test
public void testContentNegotiation() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(Person.class);
List<View> viewList = new ArrayList<View>();
viewList.add(new MappingJackson2JsonView());
viewList.add(new MarshallingView(marshaller));
ContentNegotiationManager manager = new ContentNegotiationManager(
new HeaderContentNegotiationStrategy(), new FixedContentNegotiationStrategy(MediaType.TEXT_HTML));
ContentNegotiatingViewResolver cnViewResolver = new ContentNegotiatingViewResolver();
cnViewResolver.setDefaultViews(viewList);
cnViewResolver.setContentNegotiationManager(manager);
cnViewResolver.afterPropertiesSet();
MockMvc mockMvc =
standaloneSetup(new PersonController())
.setViewResolvers(cnViewResolver, new InternalResourceViewResolver())
.build();
mockMvc.perform(get("/person/Corea"))
.andExpect(status().isOk())
.andExpect(model().size(1))
.andExpect(model().attributeExists("person"))
.andExpect(forwardedUrl("person/show"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.person.name").value("Corea"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_XML))
.andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
}
示例7: viewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
@ConditionalOnBean(ViewResolver.class)
@ConditionalOnMissingBean(name = "viewResolver", value = ContentNegotiatingViewResolver.class)
public ContentNegotiatingViewResolver viewResolver(BeanFactory beanFactory) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(
beanFactory.getBean(ContentNegotiationManager.class));
// ContentNegotiatingViewResolver uses all the other view resolvers to locate
// a view so it should have a high precedence
resolver.setOrder(Ordered.HIGHEST_PRECEDENCE);
return resolver;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:WebMvcAutoConfiguration.java
示例8: viewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ContentNegotiatingViewResolver viewResolver(BeanFactory beanFactory) {
ContentNegotiatingViewResolver contentNegotiatingViewResolver = new ContentNegotiatingViewResolver();
contentNegotiatingViewResolver.setContentNegotiationManager(beanFactory.getBean(ContentNegotiationManager.class));
contentNegotiatingViewResolver.setViewResolvers(Arrays.asList(pungweViewResolver()));
contentNegotiatingViewResolver.setDefaultViews(Arrays.asList(mappingJackson2JsonView()));
contentNegotiatingViewResolver.setOrder(Ordered.HIGHEST_PRECEDENCE);
return contentNegotiatingViewResolver;
}
示例9: testContentNegotiation
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Test
public void testContentNegotiation() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(Person.class);
List<View> viewList = new ArrayList<View>();
viewList.add(new MappingJacksonJsonView());
viewList.add(new MarshallingView(marshaller));
ContentNegotiationManager manager = new ContentNegotiationManager(
new HeaderContentNegotiationStrategy(), new FixedContentNegotiationStrategy(MediaType.TEXT_HTML));
ContentNegotiatingViewResolver cnViewResolver = new ContentNegotiatingViewResolver();
cnViewResolver.setDefaultViews(viewList);
cnViewResolver.setContentNegotiationManager(manager);
cnViewResolver.afterPropertiesSet();
MockMvc mockMvc =
standaloneSetup(new PersonController())
.setViewResolvers(cnViewResolver, new InternalResourceViewResolver())
.build();
mockMvc.perform(get("/person/Corea"))
.andExpect(status().isOk())
.andExpect(model().size(1))
.andExpect(model().attributeExists("person"))
.andExpect(forwardedUrl("person/show"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.person.name").value("Corea"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_XML))
.andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
}
示例10: contentNegotiatingViewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ViewResolver contentNegotiatingViewResolver(ContentNegotiationManager manager) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(manager);
return resolver;
}
示例11: contentViewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Autowired
@Bean
public ContentNegotiatingViewResolver contentViewResolver(
@Qualifier("contentNegotiationManagerFactory") ContentNegotiationManager contentNegotiationManager) {
ContentNegotiatingViewResolver res = new ContentNegotiatingViewResolver();
res.setContentNegotiationManager(contentNegotiationManager);
res.setDefaultViews(Arrays.asList(new MappingJackson2JsonView()));
return res;
}
示例12: contentNegotiatingViewResolver
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ContentNegotiatingViewResolver contentNegotiatingViewResolver (final ContentNegotiationManager manager) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver ();
resolver.setContentNegotiationManager (manager);
return resolver;
}