StringHttpMessageConverter编码的问题

 项目在运行某一个模块的时候,浏览器输出提示信息,如下图片所示

            encoding
控制台打印的[DEBUG]信息如下:

debug]
 StringHttpMessageConverter默认使用的是ISO-8859-1的格式,修改方式如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>text/plain;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
</bean>
</list>
</property>
</bean>

此外,上述代码要写在<mvc:annotation-driven>之前,因为它会在启动时自动注册RequestMappingHandlerAdapter。