MybatisPlus代码生成器

package com.sfj.generator.plus;

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

/**
 * mybatis-plus 代码生成器
 *
 * @author wzy [email protected]
 * @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>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
        dependency>
        <dependency>
            <groupId>com.baomidougroupId>
            <artifactId>mybatis-plusartifactId>
            <version>3.5.3version>
        dependency>
        <dependency>
            <groupId>org.freemarkergroupId>
            <artifactId>freemarkerartifactId>
            <version>2.3.30version>
        dependency>
        <dependency>
            <groupId>com.baomidougroupId>
            <artifactId>mybatis-plus-generatorartifactId>
            <version>3.5.3version>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
        dependency>

你可能感兴趣的:(java,tomcat,开发语言)