Mybatis-Plus代码生成模块代码:
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.NamingStrategy;
public class AutoMapper {
public static void main(String[] args) {
AutoGenerator ag = new AutoGenerator();
// 1. 全局配置
GlobalConfig gc = new GlobalConfig();
// 设置代码涩会给你成目录,磁盘的目录
String path = System.getProperty("user.dir");
gc.setOutputDir(path + "/src/main/java");
// 设置设置生成类的命名规则
gc.setMapperName("%sMapper");
gc.setServiceName("%sService");
gc.setServiceImplName("%sServiceImpl");
// gc.setEntityName("%sEntity");
gc.setControllerName("%sController");
gc.setAuthor("ManolinCoder");//设置作者
gc.setIdType(IdType.ID_WORKER);
// gc.setOpen(false);
ag.setGlobalConfig(gc);
// 2. 数据源配置
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/springdb?useUnicode=true&useSSL=false&characterEncoding=utf8");
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("root");
ag.setDataSource(dsc);
// 3. 包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName("order");
pc.setParent("com.wkcto");
ag.setPackageInfo(pc);
// 4. 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
ag.setStrategy(strategy);
// 5. 执行代码
ag.execute();
}
}
参考官网: https://baomidou.com/guide/generator.html
标签:代码生成,generator,baomidou,import,Mybatis,Plus,com,dsc,gc From: https://www.cnblogs.com/mingcoder/p/18498053