Mybatis-plus 代码生成器(新)工具类

代码生成器大大提高了工作效率,可根据数据库表生成Entity类,Controller类,Service类和实现类,Mapper类和对应的XML文件。

适用版本:mybatis-plus-generator 3.5.1 及其以上版本,对历史版本不兼容!

一、项目中添加依赖(我建的maven工程)

        <!--mybatisPlus--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.1</version></dependency><!--mybatis-plus--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.5.1</version></dependency><!-- velocity --><dependency><groupId>org.apache.velocity</groupId><artifactId>velocity-engine-core</artifactId><version>2.3</version></dependency><!-- freemarker --><dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.31</version></dependency><!-- mysql --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency>

二、创建代码生成器工具类

package com.fzshuai.generator;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;import java.util.ArrayList;
import java.util.Collections;
import java.util.List;/*** mybatis-plus代码生成器** @author fzshuai* @date 2022/03/13 16:45* @since 1.0*/
public class CodeGeneratorApplication {public static void main(String[] args) {List<String> tables = new ArrayList<>();tables.add("t_admin");// 项目路径String projectPath = System.getProperty("user.dir");// 代码生成器FastAutoGenerator.create("jdbc:mysql://localhost:3306/eoffice_fzs?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai", "root", "123456")// 全局配置.globalConfig(builder -> {// 作者builder.author("fzshuai")// 输出路径.outputDir(projectPath + "/eoffice-generator/src/main/java")// 禁止打开输出目录.disableOpenDir()// 开启swagger.enableSwagger()// 注释日期.commentDate("yyyy/MM/dd HH:mm")// 开启覆盖之前生成的文件.fileOverride();}).packageConfig(builder -> {builder.parent("com.fzshuai").moduleName("generator").entity("pojo").service("service").serviceImpl("service.impl").controller("controller").mapper("mapper").xml("mapper").pathInfo(Collections.singletonMap(OutputFile.mapperXml, projectPath + "/eoffice-generator/src/main/resources/mapper/"));}).strategyConfig(builder -> {builder.addInclude(tables)// 增加过滤表前缀.addTablePrefix("t_")// service策略配置.serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImpl")// entity策略配置.entityBuilder()// 数据库表映射到实体的命名策略.naming(NamingStrategy.underline_to_camel)// 数据库表字段映射到实体的命名策略.columnNaming(NamingStrategy.no_change)// 开启lombok模型.enableLombok()// controller策略设置.controllerBuilder().formatFileName("%sController").enableRestStyle().enableHyphenStyle()// mapper策略设置.mapperBuilder()// 生成通用的resultMap.enableBaseResultMap().enableBaseColumnList().superClass(BaseMapper.class).formatMapperFileName("%sMapper").enableMapperAnnotation().formatXmlFileName("%sMapper");})// 使用Freemarker引擎模板,默认的是Velocity引擎模板.templateEngine(new FreemarkerTemplateEngine()).execute();}}

Mybatis-plus 代码生成器(新)工具类相关推荐

  1. 【Android】详解7.0带来的新工具类:DiffUtil

    本文出自: [张旭童的博客] 博客地址:http://blog.csdn.net/zxt0601/article/details/52562770 一 概述 DiffUtil是support-v7:2 ...

  2. 详解7.0带来的新工具类:DiffUtil

    转: 详解7.0带来的新工具类:DiffUtil 一 概述 DiffUtil是support-v7:24.2.0中的新工具类,它用来比较两个数据集,寻找出旧数据集->新数据集的最小变化量. 说到 ...

  3. 详解Android 7.0带来的新工具类:DiffUtil

    [size=large]一 概述[/size] DiffUtil是support-v7:24.2.0中的新工具类,它用来比较两个数据集,寻找出旧数据集->新数据集的最小变化量. 说到数据集,相信 ...

  4. SpringBoot实战:整合Redis、mybatis,封装RedisUtils工具类等(附源码)

    创建SpringBoot项目 在线创建方式 网址:https://start.spring.io/ 然后创建Controller.Mapper.Service包 SpringBoot整合Redis 引 ...

  5. Spring Boot实战:整合Redis、MyBatis,封装RedisUtils工具类

    创建 Spring Boot 项目 在线创建方式 网址:https://start.spring.io/ 然后创建Controller.Mapper.Service包 SpringBoot整合Redi ...

  6. SpringBoot整合Redis+mybatis,封装RedisUtils工具类等实战(附源码)

    点击上方蓝色字体,选择"标星公众号" 优质文章,第一时间送达 关注公众号后台回复pay或mall获取实战项目资料+视频 作者:陈彦斌 cnblogs.com/chenyanbin/ ...

  7. SpringBoot实战:整合Redis、mybatis,封装RedisUtils工具类等

    创建SpringBoot项目 在线创建方式 网址:https://start.spring.io/ 然后创建Controller.Mapper.Service包 SpringBoot整合Redis 引 ...

  8. mybatis学习(4):工具类和实体类的创建

    配置文件 db.properties jdbc.driver=com.oracle.jdbc.OracleDriver jdbc.url=jdbc:oracle:thin:@127.0.0.1:152 ...

  9. 新的工具类DiffUtil,让RecyclerView上天

    1 概述 此篇文章转自鸿洋. DiffUtil是support-v7:24.2.0中的新工具类,它用来比较两个数据集,寻找出旧数据集->新数据集的最小变化量. 说到数据集,相信大家知道它是和谁相 ...

  10. 加密封装 怎么把_不要再封装各种Util工具类了,这个神级框架值得拥有!

    Hutool 谐音 "糊涂",寓意追求 "万事都作糊涂观,无所谓失,无所谓得" 的境界. Hutool 是一个 Java 工具包,也只是一个工具包,它帮助我们简 ...

最新文章

  1. Spring Autowired 注入失败总是Null
  2. [Recompose] Pass a React Prop to a Stream in RxJS
  3. linux kernl网址
  4. 代码编译 Compile、Make、Build 的区别
  5. XCode8 App上传AppStore更新
  6. 剑指Offer - 面试题51. 数组中的逆序对(归并排序,求逆序对)
  7. 2022年中国物联网行业研究报告
  8. 两个listmap合并去重_单机亿级规模题库去重,如果是你会怎么做?
  9. 分享一个debian系统优秀的镜像源
  10. python入门经典代码-python经典入门学习锦集就这篇够了,强烈建议收藏!
  11. What?什么是区块链?你不知道就太low了
  12. windows下安装rabbitmq以及php扩展amqp
  13. 乐优商城(04)--商品规格
  14. 走进音视频的世界——杜比音效之AC3与AC4
  15. python问卷星微信登录_Python+Selenium自动刷问卷星问卷
  16. Linux gcc编译程序时,-I(大写 i )、-L (大写 L)、-I(小写 L )的作用与区别
  17. ningx突然403权限拒绝解决方案
  18. 寂然安静到鸿蒙翻译,明道篇
  19. 波澜不惊 波澜不惊波澜不惊
  20. [每天读一点英文:那些给我勇气的句子] alone but not lonely

热门文章

  1. php第三方支付sdk,第三方支付 SDK
  2. matlab经纬度距离方位角,计算经纬度、距离、方位角(示例代码)
  3. python 余弦值,Python向量余弦值 Python 求向量的余弦值操作
  4. 怎么把外部参照合并到图纸_如何在CAD制图中将两个图合并到一个图纸上
  5. 高分3号介绍及PIE使用
  6. Vue常用组件库集合---kalrry
  7. MFC工程中划定ROI区域
  8. uniapp微信小程序使用canvas自定义分享名片
  9. 3D打印社团的建立和一年的经营
  10. OSI网络七层协议详解