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
;
public class CodeGenerator {
public static void main(String
[] args
) {
AutoGenerator autoGenerator
= new AutoGenerator();
GlobalConfig globalConfig
= new GlobalConfig();
globalConfig
.setOutputDir("online_edu_service/src/main/java");
globalConfig
.setAuthor("zhangqiang");
globalConfig
.setOpen(false);
globalConfig
.setFileOverride(false);
globalConfig
.setServiceName("%sService");
globalConfig
.setIdType(IdType
.ID_WORKER_STR
);
globalConfig
.setDateType(DateType
.ONLY_DATE
);
globalConfig
.setSwagger2(true);
autoGenerator
.setGlobalConfig(globalConfig
);
DataSourceConfig dataSourceConfig
= new DataSourceConfig();
dataSourceConfig
.setUrl("jdbc:mysql://localhost:3306/online_edu?serverTimezone=GMT%2B8");
dataSourceConfig
.setDriverName("com.mysql.cj.jdbc.Driver");
dataSourceConfig
.setUsername("root");
dataSourceConfig
.setPassword("123456");
dataSourceConfig
.setDbType(DbType
.MYSQL
);
autoGenerator
.setDataSource(dataSourceConfig
);
PackageConfig packageConfig
= new PackageConfig();
packageConfig
.setModuleName("");
packageConfig
.setParent("com.atguigu.edu");
packageConfig
.setController("controller");
packageConfig
.setEntity("entity");
packageConfig
.setService("service");
packageConfig
.setMapper("mapper");
autoGenerator
.setPackageInfo(packageConfig
);
StrategyConfig strategy
= new StrategyConfig();
strategy
.setInclude("edu_teacher");
strategy
.setNaming(NamingStrategy
.underline_to_camel
);
strategy
.setTablePrefix(packageConfig
.getModuleName() + "_");
strategy
.setColumnNaming(NamingStrategy
.underline_to_camel
);
strategy
.setEntityLombokModel(true);
strategy
.setRestControllerStyle(true);
strategy
.setControllerMappingHyphenStyle(true);
autoGenerator
.setStrategy(strategy
);
autoGenerator
.execute();
}
}
修改 globalConfig.setOutputDir(“online_edu_service/src/main/java”); 修改数据源配置。
会自动生成controller、service、mapper、mapper.xml、javaBean