日期:2014-05-16  浏览次数:20638 次

spring MVC @ResponseBody AJAX中文乱码处理

关注红色字体

?

配置一:

<!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->?
?<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
??????? <property name="messageConverters">
??????????? <list>
??????????????? <ref bean="stringHttpMessageConverter" />
??????????????? <ref bean="jsonHttpMessageConverter" />
????<!-- <ref bean="marshallingHttpMessageConverter" /> -->
??????????? </list>
??????? </property>
??? </bean>
????
??? <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter" >
??? ?<property name = "supportedMediaTypes">????
???????????????????? <list>????
?????????????????????????<value>text/plain;charset=UTF-8</value>????
???????????????????? </list>????
??????????????? </property>??
??? </bean>?
??? <bean id="jsonHttpMessageConverter"??
??????? class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">??
??????? <property name="supportedMediaTypes">??
??????????? <list>??
??????????????? <value>application/json</value>??
??????????? </list>??
??????? </property>??
??? </bean>
????
?<!-- Configures support for @Controllers -->
?<mvc:annotation-driven/>??
?<mvc:default-servlet-handler />

?

配置二:

@RequestMapping(value="/sys/functiontree",produces="text/plain;charset=UTF-8")
?@ResponseBody
?public String getTreeData()