文章目录
简介:MyBatis Generator简称MBG,是MyBatis 官方出的代码生成器。
一、新建SpringBoot项目
二、新建数据库表
create table shop_goods_pics(
id int unsigned not null auto_increment comment'主键',
goods_id mediumint unsigned not null comment'商品id',
pics_big char(100) not null comment '相册原图',
pics_small char(100) not null comment '相册缩略图',
primary key (id)
)
三、在 generator.properties 中添加数据库连接信息
jdbc.driverClass=com.mysql.cj.jdbc.Driver
jdbc.connectionURL=jdbc:mysql://localhost:3306/entryLevel?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
jdbc.userId=root
jdbc.password=root
四、修改 generatorConfig.xml
4.1 修改数据源配置信息
4.2 修改生成的目标文件的路径
五、执行 Generator.java 生成目标文件
六、可能遇到的问题及其解决方法
- 问题01:
使用MyBatisGenerator生成代码报错:
The specified target project directory …does not exist
解决方案:
将xml的targetProject改为 targetProject="src/main/java" 就可以了