1.Maven依赖
<!--web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- mysql 连接驱动依赖 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--mybatis-springboot-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- mybatis-plus 依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!-- mybatis-plus-generator 依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
</dependency>
2.CodeGenerator
public static void main(String[] args) throws SQLException {
generate(Lists.newArrayList("t_role"));
}
private static void generate(List<String> targets) {
FastAutoGenerator
.create("jdbc:mysql://111.11.11.11:3306/gz-shop?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai",
"XXX",
"XXX")
.globalConfig(builder -> {
builder.author("gaozhao")
.fileOverride()
.commentDate("yyyy-MM-dd")
.outputDir("D:\\project1\\gz-shop-parent\\shop-service-order\\src\\main\\java");
})
.packageConfig(builder -> {
builder.parent("com.gz.domain")
.moduleName("shop")
.entity("entity")
.service("service")
.serviceImpl("service.impl")
.controller("controller")
.mapper("mapper")
.xml("mapper")
.pathInfo(Collections.singletonMap(OutputFile.xml, "D:\\project1\\gz-shop-parent\\shop-service-order\\src\\main\\resources\\mapper"));
})
.strategyConfig(builder -> {
builder.addInclude(targets)
.addTablePrefix("t_")
.serviceBuilder()
.formatServiceFileName("%sService")
.formatServiceImplFileName("%sServiceImpl")
.entityBuilder()
.enableLombok()
.logicDeleteColumnName("deleted")
.enableTableFieldAnnotation()
.controllerBuilder()
.formatFileName("%sController")
.enableRestStyle()
.mapperBuilder()
.formatMapperFileName("%sMapper")
.enableMapperAnnotation()
.formatXmlFileName("%sMapper");
})
.execute();
}
3.生成结构
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/13b10d5c58a8c5bb4d5538ae20e8faa4.png)