描述: mybatis generator 的作用是根据数据库自动生成 实体类、Dao接口、Mapper 映射文件。
数据库:
create table product(
id int primary key AUTO_INCREMENT,
pname varchar(20),
price double,
category_id varchar(32)
);
INSERT INTO product(pname,price,category_id) VALUES('联想',5000,'电脑');
INSERT INTO product(pname,price,category_id) VALUES('海尔',3000,'洗衣机');
INSERT INTO product(pname,price,category_id) VALUES('雷神',5000,'笔记本');
INSERT INTO product(pname,price,category_id) VALUES('JACK JONES',800,'服饰');
INSERT INTO product(pname,price,category_id) VALUES('真维斯',200,'服饰');
INSERT INTO product(pname,price,category_id) VALUES('花花公子',440,'服饰');
INSERT INTO product(pname,price,category_id) VALUES('劲霸',2000,'服饰');
INSERT INTO product(pname,price,category_id) VALUES('香奈儿',800,'奢侈品');
INSERT INTO product(pname,price,category_id) VALUES('相宜本草',200,'亲民品');
INSERT INTO product(pname,price,category_id) VALUES('面霸',5,'垃圾');
INSERT INTO product(pname,price,category_id) VALUES('好想你枣',56,'零食');
INSERT INTO product(pname,price,category_id) VALUES('香飘飘奶茶',1,'毒药');
INSERT INTO product(pname,price,category_id) VALUES('果9',1,NULL);
org.mybatis.generator
mybatis-generator-maven-plugin
1.4.0
${basedir}/src/main/resources/mybatis/generator/generatorConfig.xml
true
true
mysql
mysql-connector-java
5.1.48
List users = userMapper.selectAllUser();
for (User user : users) {
System.out.println(user);
}