zhitong.yu
7 天以前 7fc9c42987a13c1d8d2159591a5803e70518827f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.hxzk.gps.util.CodeGenerator;
 
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
 
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
 
public class CodeGenerator {
    public static void main(String[] args) {
        // 数据库连接信息
        String url = "jdbc:mysql://localhost:3306/hxzkuwb?useSSL=false&serverTimezone=Asia/Shanghai";
        String username = "root";
        String password = "hxzk20151102";
 
        // 自定义 mapper.xml 的输出路径
        Map<OutputFile, String> pathInfo = new HashMap<>();
        pathInfo.put(OutputFile.xml, "src/main/resources/mapper/ThreeModel");
 
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    // 设置作者
                    builder.author("YuZhiTong")
                            // 禁止覆盖已存在的文件
                            .fileOverride()
                            // 输出目录,这里设置为项目根目录下的 temp 目录,其他文件会生成到该目录下,mapper.xml 会按照自定义路径生成
                            .outputDir("src\\main\\java");
                })
                .packageConfig(builder -> {
                    // 设置父包名
                    builder.parent("com.hxzk")
                            // 设置模块名
                            .moduleName("gps")
                            .entity("entity.ThreeModel")
                            .service("service.ThreeModel")
                            .serviceImpl("service.impl.ThreeModel")
                            .mapper("mapper.ThreeModel")
                            // 自定义路径信息
                            .pathInfo(pathInfo);
                })
                .strategyConfig(builder -> {
                    // 设置需要生成的表名
                    builder.addInclude(Collections.singletonList("tb_threemodel"))
                            // 设置过滤表前缀
                            .addTablePrefix("t_", "c_");
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}