ssm框架插入mysql数据库中文乱码问题解决

时间:2020-12-28 06:35:32

1.      检查web.xml

    <!-- 编码过滤器 --> 

    <filter> 

        <filter-name>encodingFilter</filter-name> 

        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 

        <async-supported>true</async-supported> 

        <init-param> 

            <param-name>encoding</param-name> 

            <param-value>UTF-8</param-value> 

        </init-param> 

    </filter> 

    <filter-mapping> 

        <filter-name>encodingFilter</filter-name> 

        <url-pattern>/*</url-pattern> 

    </filter-mapping> 

 

2.      检查建表脚本:

CREATE TABLE `t_user_info` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `user_name` varchar(40) NOT NULL COMMENT '用户名',

  `password` varchar(255) NOT NULL COMMENT '密码',

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户信息表';

 

3.      检查项目工程及jsp/java/xml文件

 ssm框架插入mysql数据库中文乱码问题解决

4.      检查jdbc.properties

url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=UTF-8

(详见:http://blog.csdn.net/lj402159806/article/details/54139131