需要在spring-mvc.xml中进行一些配置。
一、问题场景
ssm框架尝试输出中文,结果输出的中文全部变成问号。
console无报错信息,尝试更换浏览器编码无反应。
二、尝试解决
在spring-mvc.xml中配置一个bean:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<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/plain;charset=UTF-8</value> </list> </property> </bean> </list> </property> </bean> |
就能解决中文的输出问题了。
三、总结
spring mvc为了统一编码有非常多种配置方式,也许还有很多方法可以解决这个问题。