概述

从前端传过来的数据如果包含中文,中文会变成乱码

解决办法

在web.xml中添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
<!--配置Spring MVC的乱码过滤-->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>