spring3.1中@ResponseBody返回中文乱码

来源:互联网 发布:mysql quarter 编辑:程序博客网 时间:2024/04/29 07:47

1、spring3.1推荐使用org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter

(老版本:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter)


2、 <mvc:annotation-driven />配置到编码转换器后面


<?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.1.xsd    http://www.springframework.org/schema/context    http://www.springframework.org/schema/context/spring-context-3.1.xsd    http://www.springframework.org/schema/mvc    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">  <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">  <property name="messageConverters">  <list>  <bean class="org.springframework.http.converter.StringHttpMessageConverter">    <property name="supportedMediaTypes">  <list>  <value>text/html;charset=UTF-8</value>  </list>  </property>  </bean>  </list>  </property>  </bean>    <mvc:annotation-driven />  </beans>


0 0