多视图配置
ContentNegotiatingViewResolver
favorParameter
默认为true,表示支持参数匹配,可以根据请求参数的值确定MIME类型,默认的请求参数为format,如: /user/view?id=12&format=json
mediaTypes
根据请求参数值和MIME类型的映射列表
<property name="mediaTypes">
<map>
<entry key="html" value="text/html;charset=UTF-8"/>
<entry key="json" value="application/json;charset=UTF-8"/>
<entry key="xml" value="application/xml;charset=UTF-8"/>
</map>
</property>
viewResolvers
网页视图解析器
例:
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="favorParameter" value="true"></property>
<property name="defaultContentType" value="text/html"></property>
<property name="mediaTypes">
<map>
<entry key="html" value="text/html;charset=UTF-8"></entry>
<entry key="json" value="application/json;charset=UTF-8"></entry>
<entry key="xml" value="application/xml;chaerset=UTF-8"></entry>
</map>
</property>
<property name="viewResolvers">
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</property>
</bean>