<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plusgenerator</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-enginecore</artifactId>
<version>2.0</version>
</dependency>
public class MyBatisPlusGenerator {
public static void main(String[] args) {
GlobalConfig config = new GlobalConfig();
config.setActiveRecord(true)
.setAuthor("作者")
.setOutputDir("代码生成位置")
.setFileOverride(true)
.setIdType(IdType.AUTO)
.setDateType(DateType.ONLY_DATE)
.setServiceName("%sService")
.setEntityName("%sDO")
.setBaseResultMap(true)
.setActiveRecord(false)
.setBaseColumnList(true);
DataSourceConfig dsConfig = new DataSourceConfig();
dsConfig.setDbType(DbType.MYSQL)
.setDriverName("com.mysql.cj.jdbc.Driver")
.setUrl("jdbc:mysql://127.0.0.1:3306/t_user?useSSL=false&serverTimezone=Asia/Shanghai")
.setUsername("root")
.setPassword("root");
StrategyConfig stConfig = new StrategyConfig();
stConfig.setCapitalMode(true)
.setNaming(NamingStrategy.underline_to_camel)
.setEntityLombokModel(true)
.setRestControllerStyle(true)
.setInclude("table1","table2","table3");
PackageConfig pkConfig = new PackageConfig();
pkConfig.setParent("com.qwe")
.setMapper("mapper")
.setService("service")
.setController("controller")
.setEntity("model")
.setXml("mapper");
AutoGenerator ag = new AutoGenerator();
ag.setGlobalConfig(config)
.setDataSource(dsConfig)
.setStrategy(stConfig)
.setPackageInfo(pkConfig);
ag.execute();
System.out.println("=======代码⽣成完毕 ========");
}
}