表单提交中文字段,使用默认设置,乱码。
全部统一为utf8。服务器为centos,只做演示,没考虑其他平台浏览器编码。
1.将mysql相关配置全改为utf8。 vim /etc/my.cnf
[mysqld] datadir=/var/lib/mysql #datadir=/home/mysql socket=/var/lib/mysql/mysql.sock #socket=/home/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] #log-error=/var/log/mysqld.log log-error=/var/log/mysqld.log #pid-file=/var/run/mysqld/mysqld.pid pid-file=/var/run/mysqld/mysqld.pid #add by user default-character-set=utf8 [mysqld] init_connect=’SET NAMES utf8’ default-character-set=utf8 [mysql] default-character-set=utf8
2.创建数据库 utf8
REATE DATABASE `databasename` CHARACTER SET ‘utf8‘ COLLATE ‘utf8_general_ci‘;
3.创建表也utf8
CREATE TABLE IF NOT EXISTS suploadfileinfo ( id INT auto_increment primary key not null, filename VARCHAR(255), filesize VARCHAR(255), time TIMESTAMP DEFAULT now() ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4. play framework连接mysql时也utf8. conf/application.conf
db.default.driver= com.mysql.jdbc.Driver db.default.url="jdbc:mysql://localhost/machinelearning?useUnicode=true&characterEncoding=UTF-8" db.default.username=root db.default.password=""
时间: 2024-07-29 07:18:33