1. Spring 返回视图采用了ViewResolver,如果一般是jsp的话,可以采用InternalResourceViewResolver。

2.还可以通过ContentNegotiatingViewResolver来返回不同种类的视图,具体是是根据MediaTypes。

3. 一共有三种方式:使用扩展名、使用http request header的Accept、使用参数

他们直接的关系是:

1. If the requested path has a file extension and if the setFavorPathExtension(boolean) property is true, the mediaTypes property is inspected for a matching media type.
2. If the request contains a parameter defining the extension and if the setFavorParameter(boolean) property is true, the mediaTypes property is inspected for a matching media type. 
The default name of the parameter is format and it can be configured using the parameterName property.
3. If there is no match in the mediaTypes property and if the Java Activation Framework (JAF) is both enabled and present on the class path, FileTypeMap.getContentType(String) is used instead.
4. If the previous steps did not result in a media type, and ignoreAcceptHeader is false, the request Accept header is used.
Once the requested media type has been determined, this resolver queries each delegate view resolver for a View and determines if the requested media type is compatible with the view's content type). The most compatible view is returned.

Spring ContentNegotiatingViewResolver的更多相关文章

  1. Spring4 MVC ContentNegotiatingViewResolver多种输出格式实

    前段时间在一个项目里面发现,针对Excel的处理没有一个公用的视图,来个下载的需求就要自己去写一堆POI的东西,终于有一天给我也来了几个,还是按照以前的方式来写,写多了真心想吐,后面想想还是有必要整个 ...

  2. Spring4 MVC ContentNegotiatingViewResolver多种输出格式实例

    本文演示支持多种输出格式,这里 Spring4 MVC应用程序使用了 Spring ContentNegotiatingViewResolver .我们将生成应用程序输出XML,JSON,PDF,XL ...

  3. Spring MVC 之 ContentNegotiatingViewResolver

    我们已经知道 对于 RequestMappingInfoHandlerMapping, 它在对带有后缀的http 请求进行匹配的时候,如果找不到精确的pattern, 那么就会 pattern+.* ...

  4. Spring 梳理 - ContentNegotiatingViewResolver

    ContentNegotiatingViewResolver,这个视图解析器允许你用同样的内容数据来呈现不同的view.它支持如下面描述的三种方式: 1)使用扩展名http://localhost:8 ...

  5. 基于Spring+SpringMVC+Mybatis的Web系统搭建

    系统搭建的配置大同小异,本文在前人的基础上做了些许的改动,重写数据库,增加依据权限的动态菜单的实现,也增加了后台返回json格式数据的配置,详细参见完整源码. 主要的后端架构:Spring+Sprin ...

  6. Spring中文文档

    前一段时间翻译了Jetty的一部分文档,感觉对阅读英文没有大的提高(*^-^*),毕竟Jetty的受众面还是比较小的,而且翻译过程中发现Jetty的文档写的不是很好,所以呢翻译的兴趣慢慢就不大了,只能 ...

  7. Spring学习笔记之五----Spring MVC

    Spring MVC通常的执行流程是:当一个Web请求被发送给Spring MVC Application,Dispatcher Servlet接收到这个请求,通过HandlerMapping找到Co ...

  8. spring配置文件

    pom文件: <properties> <commons-lang.version>2.6</commons-lang.version> <slf4j.ver ...

  9. Spring MVC视图解析器

    Spring MVC提供的视图解析器使用ViewResolver进行视图解析,实现浏览器中渲染模型.ViewResolver能够解析JSP.Velocity模板.FreeMarker模板和XSLT等多 ...

随机推荐

  1. pycharm5工具免费分享及安装教程

    好东西,就要分享,最近在捣鼓Python,所以就找个pycharm5工具,感觉挺好用的. 废话不多说了,所见即所得: 百度云盘分享:http://pan.baidu.com/s/1sk9k4Nj 密码 ...

  2. 教你一步搭建Flume分布式日志系统

    在前篇几十条业务线日志系统如何收集处理?中已经介绍了Flume的众多应用场景,那此篇中先介绍如何搭建单机版日志系统. 环境 CentOS7.0 Java1.8 下载 官网下载 http://flume ...

  3. 【WPF】如何获取命令行参数

    应用程序以 Main 方法为入口点,如果为 Main 方法指定一个 string[] 类型的参数,在程序运行时,这个参数会获取到传递给应用程序的命令行参数. 而 WPF 应用程序比较特殊,因为在VS中 ...

  4. Python Tkinter学习(1)——第一个Tkinter程序

    注:本文可转载,转载请注明出处:http://www.cnblogs.com/collectionne/p/6885066.html.格式修改未完成. Tkinter资料 Python Wiki, T ...

  5. java面试题之int和Integer的区别

    int和Integer的区别 1.Integer是int的包装类,int则是java的一种基本数据类型 2.Integer变量必须实例化后才能使用,而int变量不需要 3.Integer实际是对象的引 ...

  6. js背景自适应,学到了

    最近在做一个项目,要求实现背景自适应,何为背景自适应呢? 1.如果背景图高度不够,背景height是100%,background-size就应该是 100% auto 2.如果背景图宽度不够,背景w ...

  7. 影响国内WinCE7发展的最大障碍是没有D版下载

    WinCE红火的时代已经过去,做嵌入式系统时考虑WinCE的越来越少,网络上相关文章也是越来越少. 但真正用过WinCE的应该有体会,它集成了文件系统,tcp/ip,GUI系统,usb驱动,就这些,你 ...

  8. (转)导出EXCEL时科学计数法问题

    //1)  文本:vnd.ms-excel.numberformat:@ //2)  日期:vnd.ms-excel.numberformat:yyyy/mm/dd //3)  数字:vnd.ms-e ...

  9. 借用mysql 或者其他数据库 处理MSSQL 2016前处理导入特殊字符

    MSSQL 2016支持了utf8编码的文件,之前处理比较麻烦的bcp 方式导入特殊字符一下子就方便了. 但是之前的版本,处理起来还是有一点麻烦.这次处理使用的数据库版本是sql server 201 ...

  10. C#开发移动应用系列(2.使用WebView搭建WebApp应用)

    前言 上篇文章地址:C#开发移动应用系列(1.环境搭建) 嗯..一周了 本来打算2天一更的 - - ,结果 出差了..请各位原谅.. 今天我们来讲一下使用WebView搭建WebApp应用. 说明一下 ...