Spring - 项目中文UTF-8完美支持配置


1.eclipse项目属性,设置utf-8


2.pom中

    
        
			
				org.eclipse.jetty
				jetty-maven-plugin
				${jetty.version}
			
			
				maven-compiler-plugin
 				
        			UTF-8
       			
			
        
    




3.每一句


response.setContentType("text/json;charset=UTF-8");




4.POST时: accept-charset="UTF-8"


5.dialect自定义,保证每张表建立为UTF-8编码

public class MySQL5DialectUTF8 extends MySQL5InnoDBDialect {
	
    @Override  
    public String getTableTypeString() {  
        return " ENGINE=InnoDB DEFAULT CHARSET=utf8";    
    }
}


配置文件指定:

hibernate.dialect=automobile.util.config.MySQL5DialectUTF8




6.数据库修改,MySQL默认字符集不是UTF-8 (以下来源地址 http://www.linuxidc.com/Linux/2013-11/93011.htm)

①打开my.cnf文件修改

sudo gedit /etc/mysql/my.cnf


②在[mysqld]下添加内容:

character-set-server=utf8

collation-server=utf8_general_ci

skip-character-set-client-handshake


③重启mysql

sudo service mysql restart


④进入mysql查看字符集

mysql> show variables like 'collation_%';

mysql> show variables like 'character_set_%';









你可能感兴趣的:(Spring - 项目中文UTF-8完美支持配置)