You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.0 KiB
80 lines
3.0 KiB
package com.company.project; |
|
|
|
import com.baomidou.mybatisplus.annotation.DbType; |
|
import com.baomidou.mybatisplus.annotation.IdType; |
|
import com.baomidou.mybatisplus.generator.AutoGenerator; |
|
import com.baomidou.mybatisplus.generator.config.DataSourceConfig; |
|
import com.baomidou.mybatisplus.generator.config.GlobalConfig; |
|
import com.baomidou.mybatisplus.generator.config.PackageConfig; |
|
import com.baomidou.mybatisplus.generator.config.StrategyConfig; |
|
import com.baomidou.mybatisplus.generator.config.rules.DateType; |
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; |
|
import org.junit.Test; |
|
|
|
/** |
|
* @Author chen |
|
* @DATE 2021/8/10 15:42 |
|
* @Version 1.0 |
|
*/ |
|
public class CodeGenerator { |
|
|
|
@Test |
|
public void run() { |
|
|
|
// 1、创建代码生成器 |
|
AutoGenerator mpg = new AutoGenerator(); |
|
|
|
// 2、全局配置 |
|
GlobalConfig gc = new GlobalConfig(); |
|
String projectPath = System.getProperty("user.dir"); |
|
gc.setOutputDir(projectPath + "/src/main/java"); |
|
|
|
gc.setAuthor("cheney");//设置作者 |
|
gc.setOpen(false); //生成后是否打开资源管理器 |
|
gc.setFileOverride(false); //重新生成时文件是否覆盖 |
|
gc.setServiceName("%sService"); //去掉Service接口的首字母I |
|
gc.setIdType(IdType.AUTO); //主键策略 |
|
gc.setDateType(DateType.ONLY_DATE);//定义生成的实体类中日期类型 |
|
gc.setSwagger2(true);//开启Swagger2模式 |
|
|
|
mpg.setGlobalConfig(gc); |
|
|
|
// 3、数据源配置 |
|
DataSourceConfig dsc = new DataSourceConfig(); |
|
dsc.setUrl("jdbc:mysql://139.9.47.170:3306/iasf?serverTimezone=GMT%2B8"); |
|
dsc.setDriverName("com.mysql.cj.jdbc.Driver"); |
|
dsc.setUsername("root"); |
|
dsc.setPassword("HuoRan@2021"); |
|
dsc.setDbType(DbType.MYSQL); |
|
mpg.setDataSource(dsc); |
|
|
|
// 4、包配置 |
|
PackageConfig pc = new PackageConfig(); |
|
pc.setParent("com.huoran.iasf"); |
|
//pc.setModuleName("occupationlab"); //模块名 |
|
pc.setController("controller"); |
|
pc.setEntity("entity"); |
|
pc.setService("service"); |
|
pc.setServiceImpl("service.impl"); |
|
pc.setMapper("mapper"); |
|
mpg.setPackageInfo(pc); |
|
|
|
// 5、策略配置 |
|
StrategyConfig strategy = new StrategyConfig(); |
|
strategy.setInclude("sys_footer_setup","sys_footer_setup_scope_of_application"); |
|
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略 |
|
// strategy.setTablePrefix("sys_"); //生成实体时去掉表前缀 |
|
|
|
strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略 |
|
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作 |
|
|
|
strategy.setRestControllerStyle(true); //restful api风格控制器 |
|
strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符 |
|
|
|
mpg.setStrategy(strategy); |
|
|
|
|
|
// 6、执行 |
|
mpg.execute(); |
|
} |
|
}
|
|
|