mybatis-plus代码生成器 可以直接用

# Mybatis Plus 代码生成器

github地址


核心实现功能一键生成 Controller、Service、ServiceImpl、Mapper、Mapper.xml

参考文档,[Mybatis Plus 官网文档](https://mp.baomidou.com/guide/generator.html)


## 使用方法

找到CodeGeneratorMain类,查看使用示例。

#### step1
```java
//=================================step1:传入数据库连接信息构造对象===============================================
//构造器参数分别为url driver username password
MybatisPlusCodeConfig codeConfig = new MybatisPlusCodeConfig("jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC",
        "com.mysql.jdbc.Driver", "root", "admin");
```
#### step2
```java
 //=================================step2:如果不需要继承关系可以跳过整个step2===============================================
/*step2.1:如果service需要继承,那么下面两个设置2选1即可。如果不需要继承关系,可以不设置,两个都注销即可*/

//设置为继承mybatis-plus的service
codeConfig.setServiceParentPlus();

/*//设置service继承其他类
codeConfig.setServiceParentOther("cn.swust.generator.base.service.BaseService");
codeConfig.setServiceImplParentOther("cn.swust.generator.base.service.impl.BaseServiceImpl");*/

/*step2.2:如果entry和controller需要继承,不需要继承可以不设置*/
/*  codeConfig.setEntryParent("");
codeConfig.setControllerParent("");*/
```
#### step3
```java
//=================================step3:设置需要的表list===============================================
List<String> tableNames = new ArrayList<>();
for (int i = 0; i < 6; i++) {
    tableNames.add("user");//表名
    tableNames.add("role");//表名
    tableNames.add("user_role");//表名
    tableNames.add("permission");//表名
    tableNames.add("role_per");//表名
    tableNames.add("mydata");//表名
}
```
#### step4
```java
//=================================step4:执行===============================================
tableNames.forEach(tableName -> {
    codeConfig.codeGenerator(tableName, "com.example.study.dataFilter.test");
});
```

如果需要自定义,可以自行修改在resources下的模板。可以在`MybatisPlusCodeConfig`类里面自定义是否需要继承mybatis-plus的父类service

## 注:
参考https://github.com/Tellsea/mybatis-plus-code更改
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值