可以创建一个模块命名为learning-online-generator
,父工程设置为learning-online-parent
但其目录位置在learning-online
下,目录结构如下:
learning-online ├── learning-online-base ├── learning-online-content ├── learning-online-generator └── learning-online-parent
|
所需依赖如下:
pom.xml<dependencies> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.4.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> </dependencies>
|
CodeGenerator
在test目录创建代码生成工具,配置好路径和表信息。
CodeGeneratorpublic class CodeGenerator { public static void main(String[] args) { AutoGenerator mpg = new AutoGenerator();
GlobalConfig gc = new GlobalConfig(); String projectPath = System.getProperty("user.dir"); gc.setOutputDir(projectPath + "/learning-online-generator/src/main/java"); gc.setAuthor("sw-code"); gc.setOpen(false); gc.setFileOverride(false); gc.setServiceName("%sService"); gc.setIdType(IdType.NONE); mpg.setGlobalConfig(gc);
DataSourceConfig dsc = new DataSourceConfig(); dsc.setUrl("jdbc:mysql:///lo_content?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8&nullCatalogMeansCurrent=true"); dsc.setDriverName("com.mysql.cj.jdbc.Driver"); dsc.setUsername("root"); dsc.setPassword("xxxxxx"); mpg.setDataSource(dsc);
PackageConfig pc = new PackageConfig(); pc.setParent("com.swx.content"); pc.setEntity("model.po"); pc.setMapper("mapper"); pc.setService("service"); pc.setController("controller"); mpg.setPackageInfo(pc);
StrategyConfig strategy = new StrategyConfig(); strategy.setInclude("course_base", "course_market", "course_teacher", "course_category", "teachplan", "teachplan_media", "course_publish", "course_publish_pre"); strategy.setNaming(NamingStrategy.underline_to_camel); strategy.setColumnNaming(NamingStrategy.underline_to_camel); strategy.setEntityLombokModel(true);
strategy.setEntityTableFieldAnnotationEnable(true); strategy.setRestControllerStyle(true); strategy.setControllerMappingHyphenStyle(true); mpg.setStrategy(strategy);
mpg.execute(); } }
|