SpingMVC+Mybatis+Mysql中文乱码

1.使用spring的过滤器web.xml文件中加入

  <!-- Character Encoding filter 过滤乱码 -->  
        <filter>  
            <filter-name>encodingFilter</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>  
            <init-param>  
                <param-name>forceEncoding</param-name>  
                <param-value>true</param-value>  
            </init-param>  
        </filter>  
      
        <filter-mapping>  
            <filter-name>encodingFilter</filter-name>  
            <url-pattern>/*</url-pattern>  
        </filter-mapping>  

2.修改mysql的my.ini文件

设置 default-character-set=utf8,client和server的配置都需要修改,重启mysql,ok!

你可能感兴趣的:(SpingMVC+Mybatis+Mysql中文乱码)