mybatis-plus代码生成器

2023-03-28 11:41:01 浏览数 (2)

代码语言:java复制
package com.ruoyi.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

/**
 * mybatis-plus生成代码
 *
 * @author xuyt
 * @date 2023/3/28
 **/
public class CodeGen {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://xx.xx.xx.xx:3306/db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT+8",
                "root", "root")
                .globalConfig(builder -> {
                    builder.author("xuyt") // 设置作者
                            //.enableSwagger() // 开启 swagger 模式
                            .outputDir("F:\myprojects\mp-code-gen\RuoYi-Vue\ruoyi-admin\src\main\java\com\ruoyi\util\"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.exp") // 设置父包名
                            .moduleName("module") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "F:\myprojects\mp-code-gen\RuoYi-Vue\ruoyi-admin\src\main\java\com\ruoyi\util")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("t_user") // 设置需要生成的表名
                            .addTablePrefix("t_") // 设置过滤表前缀
                            
                            .entityBuilder()
                            .enableLombok()
                            .enableTableFieldAnnotation()
                            .logicDeleteColumnName("is_delete")
                            .logicDeletePropertyName("isDelete")
                            .enableFileOverride()

                            .controllerBuilder().enableFileOverride().enableRestStyle().superClass("com.xx.xx.common.core.controller.BaseController")
                            .enableHyphenStyle();
                })
                .execute();
    }
}

pom引入依赖

代码语言:html复制
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>3.5.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-generator -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.5.3</version>
        </dependency>

0 人点赞