mybaitis-plus代码生成类
1 package com.niu.iam.gen; 2 3 import com.baomidou.mybatisplus.generator.FastAutoGenerator; 4 import com.baomidou.mybatisplus.generator.config.DataSourceConfig; 5 import com.baomidou.mybatisplus.generator.config.rules.DateType; 6 7 import java.util.Arrays; 8 import java.util.Collections; 9 import java.util.List; 10 import java.util.Scanner; 11 12 /** 13 * mybatis plus 代码生成器17 */ 18 public class MybatisGenerator { 19 20 public static void main(String[] args) { 21 Scanner scanner = new Scanner(System.in); 22 System.out.println("请输入数据库名称?"); 23 String dbName = scanner.nextLine(); 24 System.out.println("请输入作者名称?"); 25 String author = scanner.nextLine(); 26 System.out.println("请输入所属父包名称?"); 27 String rootPakName = scanner.nextLine(); 28 System.out.println("请输入生成的表明(注:多个表之间使用英文逗号分隔)?"); 29 String tableNames = scanner.nextLine(); 30 31 FastAutoGenerator 32 .create(new DataSourceConfig.Builder("jdbc:mysql://172.16.1.67/" + dbName, "root", "if^Ve$yPRfRx#x48")) 33 .globalConfig(builder -> builder 34 .disableOpenDir() 35 .outputDir("D:\iam-system\src\main\java\com\mybatis\gen\tmp") // 输出路径 36 .author(author) // 作者 37 .enableSwagger() // 开启swagger 38 .dateType(DateType.ONLY_DATE) // 日期类型仅使用 Date类型 39 .commentDate("yyyy-MM-dd")) 40 .packageConfig(builder -> builder 41 .parent(rootPakName) // 父包名 42 .entity("entity") 43 .service("service") 44 .serviceImpl("service.impl") 45 .mapper("mapper") 46 .xml("mapper.xml") 47 .controller("controller")) 48 .strategyConfig(builder -> builder 49 .addInclude(getTables(tableNames)) 50 .entityBuilder().enableChainModel() 51 .enableLombok() 52 .enableFileOverride() 53 .enableTableFieldAnnotation() 54 .enableActiveRecord() 55 .controllerBuilder().enableFileOverride() 56 // .superClass(BaseController.class) 57 .enableRestStyle() 58 .mapperBuilder().enableFileOverride() 59 .enableBaseColumnList() 60 .enableBaseResultMap() 61 .serviceBuilder().enableFileOverride() 62 .build()) 63 .execute(); 64 } 65 66 /** 67 * 获取表名称 68 */ 69 private static List<String> getTables(String tableNames) { 70 return "all".equals(tableNames) ? Collections.singletonList("*") : Arrays.asList(tableNames.split(",")); 71 } 72 }