标签:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- 扫描web包,应用Spring的注解 -->
<context:component-scan base-package="com.ll.web"/>
<mvc:annotation-driven/>
<!-- 协商多种视图解析器 -->
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
p:order="0"
p:ignoreAcceptHeader="true"
p:favorPathExtension="true"
p:favorParameter="true"
p:parameterName="format"
p:defaultContentType="text/html">
<!-- 用来定义哪些扩展名(如:/user/123.json),或协商参数值(如:/user/123?format=xml)是可识别的 -->
<property name="mediaTypes">
<map>
<entry key="html" value="text/html" />
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
<property name="defaultViews">
<list>
<!-- for application/json -->
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>
<!-- for application/xml -->
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<property name="marshaller">
<bean class="org.springframework.oxm.xstream.XStreamMarshaller"/>
</property>
</bean>
</list>
</property>
</bean>
<!-- Excel及PDF视图解析器配置 -->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"
p:order="10" />
<!-- 配置视图解析器,将ModelAndView及字符串解析为具体的页面,默认优先级最低 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:order="100"
p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/resource/jsp/"
p:suffix=".jsp" />
<!-- spring mvc对静态资源的访问 -->
<mvc:resources mapping="/resource/**" location="/resource/**" />
</beans>
【Spring学习笔记-MVC-18.1】Spring MVC实现RESTful风格-同一资源,多种展现:xml-json-html
标签:
原文地址:http://www.cnblogs.com/ssslinppp/p/4676118.html