工程中用springmvc返回json格式時,中文亂碼了,看了一下springmvc源碼發現 StringHttpMessageConverter 這個類的默認編碼爲ISO-8859-1(悲劇,springmvc這麼大的東西怎麼不用utf-8,搞不懂) html
下面是解決方法, web
springmvc 的配置文件: spring
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<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>
<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>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="interceptors">
<list>
</list>
</property>
</bean>
使用這個配置要把springmvc這個<mvc:annotation-driven /> 刪掉,不要用springmvc默認的初始化配置 json