• Mybatis-plus生成工具代码


    package com.bt.springboot.generator;
    
    
    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.NamingStrategy;
    import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
    
    import java.util.Collections;
    
    /**
     * @author 
     * @Date 2022/7/5 14:58
     */
    public class MybatisPlusGenerator {
    
    	/**
    	 * 官方地址 https://baomidou.com/pages/981406/#%E6%95%B0%E6%8D%AE%E5%BA%93%E9%85%8D%E7%BD%AE-datasourceconfig}
     	 */
    
    	/**
    	 * jdbc url username password
    	 */
    	private static final String URL = "";
    	private static final String USERNAME = "";
    	private static final String PASSWORD = "";
    
    	/**
    	 * 作者
    	 */
    	private static final String AUTHOR = "";
    	/**
    	 * 输出目录
    	 */
    	private static final String OUTPUT_DIR = "";
    	/**
    	 * 父包名 com.xxx
    	 */
    	private static final String PARENT = "";
    	/**
    	 * 模块名
    	 */
    	private static final String MODULE_NAME = "";
    	/**
    	 * mapper.xml生成路径
    	 */
    	private static final String PATH_INFO = "";
    	/**
    	 * 表名
    	 */
    	private static final String TABLE_NAME = "";
    
    	public static void main(String[] args) {
    		FastAutoGenerator.create(URL, USERNAME, PASSWORD)
    				.globalConfig(builder -> {
    					builder.author(AUTHOR)
    //							.enableSwagger() //开启swagger模式
    							.fileOverride() // 覆盖已生成文件
    							.dateType(DateType.TIME_PACK)
    							.disableOpenDir()
    							.commentDate("yyyy-MM-dd")
    							.outputDir(OUTPUT_DIR);
    				})
    				.packageConfig(builder -> {
    					builder.parent(PARENT)
    							.moduleName(MODULE_NAME)  // 设置父包模块名
    							.pathInfo(Collections.singletonMap(OutputFile.xml, PATH_INFO)); // mapper.xml生成路径
    				})
    				.strategyConfig(builder -> {
    					builder.addInclude(TABLE_NAME)
    							.enableCapitalMode() // 设置大写命名
    //							.addTablePrefix("") // 设置过滤表前缀
    
    							// Entity策略配置
    							.entityBuilder()
    							.enableLombok() // 开启lombok模型
    							.enableChainModel() // 开启链式调用
    							.naming(NamingStrategy.underline_to_camel) // 数据库表映射到实体的命名策略
    							.enableTableFieldAnnotation() // 开启生成实体时生成字段注解
    
    							// Service 策略配置
    							.serviceBuilder()
    							.formatServiceFileName("%sService"); // 格式化 service 接口文件名称
    				})
    				.templateEngine(new VelocityTemplateEngine())
    				.execute();
    
    	}
    }
    
    
    • 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
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
  • 相关阅读:
    基于uniapp开发 软盒APP系统源码 软件库系统源码 全开源
    Netty的零拷贝(Zero-Copy)
    vue的基础的学习
    移动硬盘误删除要如何恢复呢?
    8.Haproxy 搭建Web集群
    如何使用 Xcode 13+ 新的列断点(Column Breakpoints)让中断位置更加精确制导
    SpringCloud——服务网关——GateWay
    LeetCode: 高频链表题目总结 - Python
    vue3+electron开发桌面应用,静态资源处理方式及路径问题总结
    Docker 使用手册
  • 原文地址:https://blog.csdn.net/IT_world_/article/details/125917917