方便下次使用直接CTRL+C ,V
导入maven依赖
<!-- start 自动生成代码--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.5.1</version> </dependency> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.28</version> <scope>compile</scope> </dependency> <!-- end 自动生成代码-->
Class代码
/** * @author :Xiaobai * @description :代码自动生成器 * @blog : https://bducds.com/ * @date :2021/11/13 15:42 */ public class BaiCode { public static void main(String[] args) { List<String> tables = new ArrayList<>(); tables.add("t_user"); tables.add("t_admin"); tables.add("t_comment"); FastAutoGenerator.create("jdbc:mysql://localhost:3306/database","root","root") .globalConfig(builder ->{ builder.author("xiaobai") .enableSwagger(). fileOverride(). outputDir(System.getProperty("user.dir")+"\\src\\main\\java") .commentDate("yyyy-MM-dd"); }).packageConfig(builder -> { builder.parent("com.bai") .moduleName("webapiapp") .entity("entity") .service("service") .serviceImpl("serviceImpl") .controller("controller") .mapper("mapper") .xml("mapper") .pathInfo(Collections.singletonMap(OutputFile.mapperXml,System.getProperty("user.dir")+"\\src\\main\\resources\\mapper")); }).strategyConfig(builder -> { builder.addInclude(tables).addTablePrefix("c_") .serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImpl") .entityBuilder().enableLombok().enableTableFieldAnnotation().controllerBuilder().formatFileName("%sController") .enableRestStyle().mapperBuilder().superClass(BaseMapper.class).formatMapperFileName("%sMapper") .enableMapperAnnotation().formatMapperFileName("%sMapper"); }).templateEngine(new FreemarkerTemplateEngine()) .execute(); } }
本文作者为Mr.Bai,转载请注明。
不错,必须顶一下!