mybatis-plus 代码生成器
- 随着反复编写代码而已,键盘上的c键和v键也早已渐渐模糊。记录一下mybatis-plus的代码生成器
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
public class CodeGeneration {
public static void main(String[] args) {
AutoGenerator autoGenerator = new AutoGenerator();
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setDateType(DateType.ONLY_DATE);
globalConfig.setOutputDir("D:\\demo\\src\\main\\java");
globalConfig.setOpen(false);
globalConfig.setFileOverride(true);
globalConfig.setActiveRecord(false);
globalConfig.setEnableCache(false);
globalConfig.setBaseResultMap(true);
globalConfig.setBaseColumnList(false);
globalConfig.setAuthor("czx");
globalConfig.setControllerName("%sController");
globalConfig.setServiceName("I%sService");
globalConfig.setServiceImplName("%sServiceImpl");
globalConfig.setMapperName("%sMapper");
globalConfig.setXmlName("%sMapper");
globalConfig.setEntityName("%s");
autoGenerator.setGlobalConfig(globalConfig);
DataSourceConfig config = new DataSourceConfig();
config.setDbType(DbType.MYSQL);
config.setDriverName("com.mysql.cj.jdbc.Driver");
config.setUsername("xc");
config.setPassword("xc");
config.setUrl("jdbc:mysql://你的数据库地址/数据库名?useSSL=false&serverTimezone=Asia/Shanghai");
autoGenerator.setDataSource(config);
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
String[] names = {"user"};
strategy.setInclude(names);
strategy.setSuperServiceClass(null);
strategy.setSuperServiceImplClass(null);
strategy.setSuperMapperClass(null);
strategy.setEntityLombokModel(true);
autoGenerator.setStrategy(strategy);
PackageConfig pc = new PackageConfig();
pc.setParent("com.tb.timebest_center");
pc.setController("controller");
pc.setService("service");
pc.setServiceImpl("service.impl");
pc.setMapper("dao");
pc.setEntity("pojo.entity");
pc.setXml("mapper");
autoGenerator.setPackageInfo(pc);
autoGenerator.execute();
}
}