MybatisPlus代码生成器

发布时间:2024年01月13日
package com.sfj.generator.plus;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

/**
 * mybatis-plus 代码生成器
 *
 * @author wzy wzynov@qq.com
 * @date 2023-12-12 09:47
 */
public class CodeGenerator {
    // 作者
    public static final String author = "wzy";
    // 数据库信息
    public static final String url = "jdbc:mysql://localhost:3306/oa_1220?characterEncoding=utf-8&useSSL=false&serverTimezone=Hongkong";
    public static final String username = "root";
    public static final String password = "root";
    public static final String include = "oa_customer_pool";// 用,隔开
    public static final String table_prefix = "oa_";// 忽略表前缀
    // 包名
    public static final String parent = "com.yitu.oa";
    public static final String entity = "entity.entity";
    public static final String mapper = "mapper";
    public static final String xml = "mapper.impl";
    public static final String service = "service";
    public static final String controller = "controller";
    
    public static void main(String[] args) {
        generate();
    }
    
    public static void generate() {
        FastAutoGenerator.create(url, username, password).globalConfig(builder -> {
                    builder.author(author) // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .disableOpenDir()// 禁止打开输出目录
                            .outputDir(System.getProperty("user.dir") + "/file"); // 指定输出目录
                }).packageConfig(builder -> {
                    builder.parent(parent) // 设置父包名
                            .entity(entity).mapper(mapper).xml(xml).service(service).controller(controller);
                }).strategyConfig(builder -> {
                    builder.addInclude(include)// 设置需要生成的表名
                            .addTablePrefix(table_prefix)// 设置忽略表前缀
                            .addFieldPrefix("f_").entityBuilder().enableLombok()// 开启lombok
                            .enableChainModel()// 开启链式
                            // .disableSerialVersionUID()// 关闭生成SerialVersionUID
                            .serviceBuilder().formatServiceImplFileName("%sServiceImp").formatServiceFileName("%sService")
                            .controllerBuilder().enableRestStyle();
                }).templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
                .execute();
    }
}

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>3.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.30</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
文章来源:https://blog.csdn.net/weixin_44512485/article/details/135505546
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。