Mybatis-Plus 代码工具生成工具 V 3.5.9

package com.snail.code.system;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.sql.Types;
import java.util.Collections;

/**
 * @author 熟透的蜗牛
 * @version 1.0
 * @description: 系统库生成代码
 * @date 2025/1/16 17:00
 */
public class SystemGenerator {

    public static void generate() {
        FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/snail-system?serverTimezone=Asia/Shanghai", "root", "root")
                .globalConfig(builder -> {
                    builder.author("熟透的蜗牛") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir("D://system") // 指定输出目录
                            .dateType(DateType.ONLY_DATE) // 设置时间类型策略
                            .commentDate("yyyy-MM-dd")// 设置注释日期格式
                            .disableOpenDir();//自动打开目录

                })
                .dataSourceConfig(builder ->
                        builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
                            int typeCode = metaInfo.getJdbcType().TYPE_CODE;
                            if (typeCode == Types.SMALLINT) {
                                // 自定义类型转换
                                return DbColumnType.INTEGER;
                            }
                            return typeRegistry.getColumnType(metaInfo);
                        })
                )
                .packageConfig(builder ->
                        builder.parent("com.snail") // 设置父包名
                                .moduleName("system") // 设置父包模块名
                                .entity("model") // 设置 Entity 包名
                                .service("service") // 设置 Service 包名
                                .serviceImpl("service.impl") // 设置 Service Impl 包名
                                .mapper("mapper") // 设置 Mapper 包名
                                .xml("mappers") // 设置 Mapper XML 包名
                                .controller("controller")// 设置 Controller 包名
                                .pathInfo(Collections.singletonMap(OutputFile.xml, "D://system")) // 设置mapperXml生成路径
                )
                .strategyConfig(builder ->

                        builder
                                //.addInclude("")  // 设置需要生成的表名
                                .addTablePrefix("sys_") // 设置过滤表前缀
                                .entityBuilder()
                                .enableLombok()

                                .serviceBuilder()
                                .formatServiceFileName("%sService")
                                .formatServiceImplFileName("%sServiceImp")
//这里配置的mybatis-plus-join 框架的包
                                .superServiceClass("com.github.yulichang.base.MPJBaseService")
                                .superServiceImplClass("com.github.yulichang.base.MPJBaseServiceImpl")

                                .mapperBuilder().superClass("com.github.yulichang.base.MPJBaseMapper")

                                .controllerBuilder().superClass("com.snail.manager.common.resdata.BaseController")
                                .enableRestStyle()


                )
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
                .execute();
        System.out.println("执行完成");

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

熟透的蜗牛

永远满怀热爱,永远热泪盈眶

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值