mybatis plus 基础代码生成器
作者:互联网
1, 复制代码 2 导入依赖 3运行main方法 ok
public class CodeGenerator {
//数据库路径
private static String url = "jdbc:mysql://192.176.17.7:3306/plus_db?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8";
private static String username = "root";
private static String password = "root";
private static String packagePath = "com.qyy.plus"; //包路径
private static String author = "qyy"; //作者
private static String prefix = ""; //前缀
private static String projectPath = "D:\\mybatisPlus\\workspace\\qyy_db\\plus"; //项目的路径,在下面自动拼接了 /src/main/java
private static String[] tables = {"tool_user"};//生成的表
public static void main(String[] args) {
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
//String projectPath = "D:\\ideaWork\\iot-coldchain";
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor(author);
gc.setOpen(false);// 生成后是否打开资源管理器
gc.setFileOverride(true);//文件是否覆盖
gc.setServiceName("%sService");//去掉Service接口的首字母I
gc.setIdType(IdType.AUTO);// 主键策略
gc.setDateType(DateType.ONLY_DATE);// 日期类型
gc.setSwagger2(false); // 实体属性 Swagger2 注解
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(url);
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername(username);
dsc.setPassword(password);
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);
// 包配置
PackageConfig pc = new PackageConfig();
// 主模块,会自动多创建一层包
//pc.setModuleName("user");
pc.setParent(packagePath);
pc.setController("controller");
pc.setService("service");
pc.setEntity("entity");
pc.setMapper("mapper");
mpg.setPackageInfo(pc);
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setInclude(tables);
strategy.setNaming(NamingStrategy.underline_to_camel);//表和实体类的命名规则
strategy.setTablePrefix(prefix);
//strategy.setTablePrefix(pc.getModuleName()+"_");
strategy.setColumnNaming(NamingStrategy.underline_to_camel);//字段映射规则
strategy.setEntityLombokModel(true);
strategy.setRestControllerStyle(true); //restfulapi风格
strategy.setControllerMappingHyphenStyle(true);//url中驼峰转连字符
mpg.setStrategy(strategy);
mpg.execute();
}
2 依赖包
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.0</version>
</dependency>
标签:代码生成,String,strategy,pc,static,plus,mybatis,gc,dsc 来源: https://blog.csdn.net/weixin_43183496/article/details/121744178