Mybatis-plus的代码生成器的配置

Mp的代码生成器代码生成文件

public class getCode {
@Test
 public void main1() {
 // 1、创建代码生成器
 AutoGenerator mpg = new AutoGenerator();
 // 2、全局配置
 GlobalConfig gc = new GlobalConfig();
 String projectPath = System.getProperty("user.dir");
 System.out.println(projectPath);
 gc.setOutputDir(projectPath + "/src/main/java");
 gc.setAuthor("atguigu");
 gc.setOpen(false); //生成后是否打开资源管理器
 gc.setFileOverride(false); //重新生成时文件是否覆盖
 /*
 * mp生成service层代码,默认接口名称第一个字母有 I
 * UcenterService
 * */
 gc.setServiceName("%sService"); //去掉Service接口的首字母I
 gc.setIdType(IdType.ID_WORKER); //主键策略
 gc.setDateType(DateType.ONLY_DATE);//定义生成的实体类中日期类型
 gc.setSwagger2(true);//开启Swagger2模式

 mpg.setGlobalConfig(gc);

// 3、数据源配置
 DataSourceConfig dsc = new DataSourceConfig();
 dsc.setUrl("jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8");
 dsc.setDriverName("com.mysql.cj.jdbc.Driver");
 dsc.setUsername("root");
 dsc.setPassword("root");
 dsc.setDbType(DbType.MYSQL);
 mpg.setDataSource(dsc);

 // 4、包配置
 PackageConfig pc = new PackageConfig();
 pc.setModuleName("serviceedu"); //模块名
 pc.setParent("com.atguigu");
 pc.setController("controller");
 pc.setEntity("entity");
 pc.setService("service");
 pc.setMapper("mapper");
 mpg.setPackageInfo(pc);

 // 5、策略配置
 StrategyConfig strategy = new StrategyConfig();
 strategy.setInclude("edu_teacher");
 strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的
命名策略
 strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀

 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();
 }
 }

配置依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>service</artifactId>
        <groupId>com.atwjw</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath   />
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>service_edu</artifactId>
    <dependencies>

        <dependency>
            <groupId>com.atwjw</groupId>
            <artifactId>server_base</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.0.5</version>
            <scope>test</scope>
        </dependency>
        <!-- 操作EasyExecl的依赖-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>2.1.1</version>
        </dependency>
    </dependencies>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

</project>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值