代码生成器(新)官网
后端代码:点击查看 LearnElementUiAndSpringBoot
提醒:LearnElementUiAndSpringBoot下载完后,在运行调试 Main.java里的main方法之前,除了utils包和Main.java文件,其他包需要先删除,否则会看不出自动生成的代码
快速入门
一、pom.xml添加依赖
<!-- velocity官网https://velocity.apache.org/engine/devel/user-guide.htmlhttps://velocity.apache.org/download.cgi#engine-->
<dependency><groupId>org.apache.velocity</groupId><artifactId>velocity-engine-core</artifactId><version>2.3</version>
</dependency>
<!-- 代码生成器新 https://baomidou.com/pages/779a6e/#%E5%AE%89%E8%A3%85-->
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.5.5</version>
</dependency>
二、使用
1:创建FastAutoGeneratorUtil.java
package com.example.learnelementuiandspringboot.utils;import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;import java.util.Collections;public class FastAutoGeneratorUtil {private static final String DIR_ROOT = "/Users/chinadragon/Desktop/intellij_idea_project/LearnElementUiAndSpringBoot/src/main/java";private static final String PKG_NAME = "com.example.learnelementuiandspringboot";public static void autoGenerator() {//代码生成器新 https://baomidou.com/pages/779a6e/#%E5%AE%89%E8%A3%85//https://blog.csdn.net/wmj20001225/article/details/132595714//https://baomidou.com/pages/779a6e/#%E5%AE%89%E8%A3%85//https://blog.csdn.net/qq_42263280/article/details/126531993FastAutoGenerator.create("jdbc:mysql://localhost:3306/db_test", "root", "123456")//全局配置(GlobalConfig).globalConfig(builder -> {builder.disableOpenDir()//禁止打开输出目录 默认值:true
// .outputDir(System.getProperty("user.dir")+"/src/main/java")//指定输出目录.outputDir(DIR_ROOT)//指定输出目录.author("国龙")
// .enableSwagger().dateType(DateType.TIME_PACK).commentDate("yyyy-MM-dd").build();})//包配置(PackageConfig).packageConfig(builder -> {builder.parent(PKG_NAME)
// .moduleName("sys") //父包模块名 默认值:无.entity("entity").service("service").serviceImpl("service.impl").mapper("mapper").xml("mapper.xml").controller("controller")
// .pathInfo(Collections.singletonMap(OutputFile.xml, "/Users/chinadragon/Desktop/intellij_idea_project/LearnElementUiAndSpringBoot/src/main/resources/mapper")).pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") + "/src/main/resources/mapper")).build();})//策略配置.strategyConfig(builder -> {builder.addInclude("book").mapperBuilder().enableMapperAnnotation().serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImp").build();}).execute();}
}
2:创建Main.java
package com.example.learnelementuiandspringboot;
import com.example.learnelementuiandspringboot.utils.FastAutoGeneratorUtil;public class Main {public static void main(String[] args) {FastAutoGeneratorUtil.autoGenerator();}
}
运行main方法后的效果
以上就是代码生成器(新):mybatis-plus-generator使用指南全部内容讲解。