mybatisplus自动生成代码

2023-01-06  本文已影响0人  Leo_23
package com.leo23.authorize;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Collections;

@SpringBootTest
class AuthorizeApplicationTests {

    @Test
    void contextLoads() {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/authorize?serverTimezone=GMT%2B8", "root", "leo493852107")
                .globalConfig(builder -> {
                    builder.author("leo23") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("~/Desktop"); // 指定输出目录

                })
                .packageConfig(builder -> { //包配置
                    builder.parent("com.leo23") // 设置父包名
                            .moduleName("") // 设置父包模块名
                            .controller("controller")
                            .entity("entity")
                            .service("service")
                            .mapper("mapper")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "~/Desktop")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> { // 策略配置
                    builder
                            .addTablePrefix("t_", "c_")
                            ; // 设置过滤表前缀
                })
                .templateEngine(new VelocityTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
                .execute();

    }

}
上一篇下一篇

猜你喜欢

热点阅读