当前位置: 首页>>代码示例>>Java>>正文


Java ContentNegotiatingViewResolver.setDefaultViews方法代码示例

本文整理汇总了Java中org.springframework.web.servlet.view.ContentNegotiatingViewResolver.setDefaultViews方法的典型用法代码示例。如果您正苦于以下问题:Java ContentNegotiatingViewResolver.setDefaultViews方法的具体用法?Java ContentNegotiatingViewResolver.setDefaultViews怎么用?Java ContentNegotiatingViewResolver.setDefaultViews使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.servlet.view.ContentNegotiatingViewResolver的用法示例。


在下文中一共展示了ContentNegotiatingViewResolver.setDefaultViews方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: contentNegotiatingViewResolver

import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ViewResolver contentNegotiatingViewResolver() {
    logger.debug("Configuring the ContentNegotiatingViewResolver");
    ContentNegotiatingViewResolver viewResolver = new ContentNegotiatingViewResolver();
    List<ViewResolver> viewResolvers = new ArrayList<ViewResolver>();

    UrlBasedViewResolver urlBasedViewResolver = new UrlBasedViewResolver();
    urlBasedViewResolver.setViewClass(JstlView.class);
    urlBasedViewResolver.setSuffix(".html");
    viewResolvers.add(urlBasedViewResolver);

    viewResolver.setViewResolvers(viewResolvers);

    List<View> defaultViews = new ArrayList<View>();
    defaultViews.add(new MappingJackson2JsonView());
    viewResolver.setDefaultViews(defaultViews);

    return viewResolver;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:20,代码来源:CloudUnitApplicationContext.java

示例2: viewResolver

import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ViewResolver viewResolver() {
	ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
	
	List<View> defaultViews = new ArrayList<View>();
	defaultViews.add(new MappingJackson2JsonView());
	resolver.setDefaultViews(defaultViews);
	resolver.setOrder(0);
	
	List<ViewResolver> viewResolvers = new ArrayList<ViewResolver>();
	InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
	internalResourceViewResolver.setPrefix("/WEB-INF/view/");
	internalResourceViewResolver.setSuffix(".jsp");
	internalResourceViewResolver.setOrder(1);
	viewResolvers.add(internalResourceViewResolver);
	resolver.setViewResolvers(viewResolvers);
	
	return resolver;
}
 
开发者ID:EnterKey,项目名称:enterkey-framework,代码行数:20,代码来源:Application.java

示例3: contentNegotiatingViewResolver

import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ViewResolver contentNegotiatingViewResolver() {
    LOGGER.debug("Configuring the ContentNegotiatingViewResolver");
    ContentNegotiatingViewResolver viewResolver = new ContentNegotiatingViewResolver();
    List<ViewResolver> viewResolvers = new ArrayList<>();

    UrlBasedViewResolver urlBasedViewResolver = new UrlBasedViewResolver();
    urlBasedViewResolver.setViewClass(JstlView.class);
    urlBasedViewResolver.setPrefix("/WEB-INF/pages/");
    urlBasedViewResolver.setSuffix(".jsp");
    viewResolvers.add(urlBasedViewResolver);

    viewResolver.setViewResolvers(viewResolvers);

    List<View> defaultViews = new ArrayList<>();
    defaultViews.add(new MappingJackson2JsonView());
    viewResolver.setDefaultViews(defaultViews);

    return viewResolver;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:21,代码来源:DispatcherServletConfiguration.java

示例4: 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;
}
 
开发者ID:gregwhitaker,项目名称:catnap,代码行数:25,代码来源:DelegatingCatnapWebMvcConfiguration.java

示例5: 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")));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolutionTests.java

示例6: 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;
}
 
开发者ID:thunderbird,项目名称:pungwecms,代码行数:10,代码来源:ModuleContextConfig.java

示例7: viewResolver

import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ContentNegotiatingViewResolver viewResolver() {
    ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
    List<ViewResolver> viewResolvers = new ArrayList<>(1);
    viewResolvers.add(jspViewResolver());
    resolver.setViewResolvers(viewResolvers);
    List<View> views = new ArrayList<>();
    views.add(jsonView());
    resolver.setDefaultViews(views);
    return resolver;
}
 
开发者ID:srinikandula,项目名称:mybus,代码行数:12,代码来源:WebApplicationConfig.java

示例8: 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")));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:40,代码来源:ViewResolutionTests.java

示例9: 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;

}
 
开发者ID:JensKapitza,项目名称:jsf-exmple,代码行数:11,代码来源:PersistenceConfig.java

示例10: contentNegotiatingViewResolver

import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; //导入方法依赖的package包/类
@Bean
public ContentNegotiatingViewResolver contentNegotiatingViewResolver() {
    ContentNegotiatingViewResolver result = new ContentNegotiatingViewResolver();
    Map<String, String> mediaTypes = new HashMap<String, String>();
    mediaTypes.put("json", MediaType.APPLICATION_JSON_VALUE);
    result.setMediaTypes(mediaTypes);
    MappingJacksonJsonView jacksonView = new MappingJacksonJsonView();
    jacksonView.setExtractValueFromSingleKeyModel(true);
    Set<String> modelKeys = new HashSet<String>();
    modelKeys.add("events");
    modelKeys.add("event");
    jacksonView.setModelKeys(modelKeys);
    result.setDefaultViews(Collections.singletonList((View) jacksonView));
    return result;
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:16,代码来源:WebMvcConfig.java


注:本文中的org.springframework.web.servlet.view.ContentNegotiatingViewResolver.setDefaultViews方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。