public static void main(String[] args) { // 需要构建一个 代码自动生成器 对象 AutoGenerator autoGenerator = new AutoGenerator(); // 配置策略 // 1、全局配置 GlobalConfig globalConfig = new GlobalConfig(); //获取系统目录 String projectPath = System.getProperty("user.dir"); globalConfig.setOutputDir(projectPath + "/src/main/java"); globalConfig.setAuthor("AbrahamCui");//作者 globalConfig.setOpen(false);//生成后是否打开所在文件夹 globalConfig.setFileOverride(false); // 是否覆盖 globalConfig.setServiceName("%Service"); // 去Service的I前缀 globalConfig.setIdType(IdType.ID_WORKER);//主键策略 globalConfig.setDateType(DateType.ONLY_DATE);//日期配置 globalConfig.setSwagger2(true);//自动配置swagger2 autoGenerator.setGlobalConfig(globalConfig);//装入 // 2、设置数据源 DataSourceConfig dsc = new DataSourceConfig(); dsc.setUrl("jdbc:mysql://localhost:3306/music?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false"); dsc.setDriverName("com.mysql.jdbc.Driver"); dsc.setUsername("root"); dsc.setPassword("123456"); dsc.setDbType(DbType.MYSQL); autoGenerator.setDataSource(dsc);//装入 // 3、包的设置 PackageConfig pc = new PackageConfig(); pc.setModuleName("music"); pc.setParent("com.javaclimb"); pc.setEntity("entity"); pc.setMapper("mapper"); pc.setService("service"); pc.setController("controller"); autoGenerator.setPackageInfo(pc);//装入 // 4、策略配置 StrategyConfig strategyConfig = new StrategyConfig(); // 设置要映射的表名 strategyConfig.setInclude("collect"); strategyConfig.setNaming(NamingStrategy.underline_to_camel); strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel); strategyConfig.setEntityLombokModel(true); // 自动lombok // 乐观锁 strategyConfig.setLogicDeleteFieldName("deleted"); // 自动填充配置 TableFill gmtCreate = new TableFill("create_time", FieldFill.INSERT); TableFill gmtModified = new TableFill("update_time", FieldFill.INSERT_UPDATE); ArrayList tableFills = new ArrayList<>(); tableFills.add(gmtCreate);//装入 tableFills.add(gmtModified);//装入 strategyConfig.setTableFillList(tableFills);//装入 strategyConfig.setRestControllerStyle(true); strategyConfig.setControllerMappingHyphenStyle(true); // localhost:8080/hello_id_2 autoGenerator.setStrategy(strategyConfig);//装入 autoGenerator.execute();//执行pom.xml和上面代码相关的依赖
org.apache.velocity velocity-engine-core2.2 com.baomidou mybatis-plus-generator3.0.5 com.baomidou mybatis-plus-boot-starter3.0.5 io.springfox springfox-swagger22.7.0 io.springfox springfox-swagger-ui2.7.0 org.projectlombok lombok1.18.6
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)