http://www.cnblogs.com/xdp-gacl/p/4261895.html
参考了这篇文章搭建了Mybaits环境,原作者有些地方没有标注使用某种编码,我是自学SQL的,所以深知编码格式的坑
1 create database mybatis; 2 use mybatis; 3 CREATE TABLE users(id INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR(20), age INT); 4 INSERT INTO users(NAME, age) VALUES('孤傲苍狼', 27); 5 INSERT INTO users(NAME, age) VALUES('白虎神皇', 27);
这里建表的时候 最好指定编码格式为UTF8
CREATE TABLE users(id INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR(20), age INT)engine = InnoDB default charset=utf8;//指定引擎为InnoDB 默认缺省编码为 utf8
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <environments default="development"> <environment id="development"> <transactionManager type="JDBC" /> <!-- 配置数据库连接信息 --> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/mybaits?characterEncoding=utf8" /> <property name="username" value="root" /> <property name="password" value="admin" /> </dataSource> </environment> </environments> <mappers> <mapper resource="pw/jonwinters/mybaits/userMapper.xml"/></mappers> </configuration>
<property name="url" value="jdbc:mysql://localhost:3306/mybaits?characterEncoding=utf8" />
这一行也改成utf8这样就不会出现编码错误了