Mybatis-Plus代码生成插件:mybatis-plus-generator-ui

 <dependency>
   <groupId>com.github.davidfantasy</groupId>
   <artifactId>mybatis-plus-generator-ui</artifactId>
   <version>1.4.5</version>
  </dependency>
  
  <dependency>
   <groupId>org.postgresql</groupId>
   <artifactId>postgresql</artifactId>
   <version>42.2.25</version>
  </dependency>
 </dependencies>

新建程序入口,以main函数的方式运行

package com.yelang;
 
import com.github.davidfantasy.mybatisplus.generatorui.GeneratorConfig;
import com.github.davidfantasy.mybatisplus.generatorui.MybatisPlusToolsApplication;
import com.github.davidfantasy.mybatisplus.generatorui.mbp.NameConverter;
 
public class GeneratorMain {
 
 public static void main(String[] args) {
  GeneratorConfig config = GeneratorConfig.builder().jdbcUrl("jdbc:postgresql://127.0.0.1:5432/test")
    .userName("rrr1").password("rrr1").driverClassName("org.postgresql.Driver")
    // 数据库schema,POSTGRE_SQL,ORACLE,DB2类型的数据库需要指定
    // .schemaName("myBusiness")
    // 如果需要修改各类生成文件的默认命名规则,可自定义一个NameConverter实例,覆盖相应的名称转换方法:
    .nameConverter(new NameConverter() {
     /**
      * 自定义Service类文件的名称规则
      */
     public String serviceNameConvert(String tableName) {
      return this.entityNameConvert(tableName) + "Service";
     }
 
     /**
      * 自定义Controller类文件的名称规则
      */
     public String controllerNameConvert(String tableName) {
      return this.entityNameConvert(tableName) + "Action";
     }
    }).basePackage("com.mybatisplustools.example").port(8068).build();
 
  MybatisPlusToolsApplication.run(config);
 
 }
 
}

在输出的日志中,可以看到程序的运行端口,以及默认的模板目录地址。在浏览器中输入访问地址http://localhost:8068/

 

 

 

 

输出配置

内置Entity、Mapper、Service、Controller等6种类型代码的模板配置,可以上传模板进行替换,并修改各类参数,配置参数已经按照影响的文件类型重新进行了分类,并加入了部分文本说明;也可以自行添加其它类型的自定义输出文件。所有的配置项都会按照项目包名进行保存,只需一次性设置就可以了。

 

 

3、策略配置

将每次生成代码时可能变动的内容加入到代码生成选项中,方便调整每次的生成策略,比如:是否覆盖原文件,生成文件的种类等等:

 

 

4、SQL配置生成

通过输入查询SQL,可自动在Mapper(Xml及Java)中生成对应的查询方法,DTO对象和ResultMap(结果集映射配置)

 

 

5、代码生成

 

posted @ 2023-02-22 11:31  陈扬天  阅读(365)  评论(0编辑  收藏  举报