当前位置: 首页 > news >正文

【java】mybatis-plus代码生成

正常的代码生成这里就不介绍了。旨在记录实现如下功能:

分布式微服务环境下,生成的entity、dto、vo、feignClient等等api模块,需要和mapper、service、controller等等分在不同的目录生成。

为什么会出现这个需求?
mybatis-plus(3.5.3.1)提供的全局配置:outputDir,该方法是entity、mapper、service、controller的文件输出目录。
如上,需要将entity和其他三个区分到不同的目录。
查看源码com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine

/*** 输出实体文件** @param tableInfo 表信息* @param objectMap 渲染数据* @since 3.5.0*/@Overrideprotected void outputEntity(TableInfo tableInfo, Map<String, Object> objectMap) {}/*** 输出Mapper文件(含xml)** @param tableInfo 表信息* @param objectMap 渲染数据* @since 3.5.0*/@Overrideprotected void outputMapper(TableInfo tableInfo, Map<String, Object> objectMap) {}/*** 输出service文件** @param tableInfo 表信息* @param objectMap 渲染数据* @since 3.5.0*/@Overrideprotected void outputService(TableInfo tableInfo, Map<String, Object> objectMap) {}/*** 输出controller文件** @param tableInfo 表信息* @param objectMap 渲染数据* @since 3.5.0*/@Overrideprotected void outputController(TableInfo tableInfo, Map<String, Object> objectMap) {}

一般都会集成自定义的文件生成,使用模板,一般的选择就是
在这里插入图片描述

上述的4个engine也就是继承了AbstractTemplateEngine,可根据自己选择的模板,再次集成,重写这4个方法:outputEntity outputMapper outputService outputController ,方法内部不需要执行相关代码, 输出的逻辑放在outputCustomFile方法内即可

源码:

@AllArgsConstructor
public class ByTemplateEngine extends BeetlTemplateEngine {private String apiOutputDir;private String serverOutputDir;@Overrideprotected void outputCustomFile(List<CustomFile> customFiles, TableInfo tableInfo, Map<String, Object> objectMap) {String packageName = String.valueOf(objectMap.get("packageName"));String entityName = String.valueOf(objectMap.get("entityName"));customFiles.forEach(customFile -> {String key = customFile.getFileName();String value = customFile.getTemplatePath();String outputPath = getPathInfo(OutputFile.parent);objectMap.put("entityKey", entityNameLower);if (StringUtil.equals(key, "controller.java")) {outputPath =serverOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"controller" + StringPool.SLASH + entityName + "Controller" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "entity.java")) {outputPath = apiOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"entity" + StringPool.SLASH + entityName + "Entity" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "mapper.java")) {outputPath =serverOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"mapper" + StringPool.SLASH + entityName + "Mapper" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "mapper.xml")) {outputPath =serverOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"mapper" + StringPool.SLASH + entityName + "Mapper" + StringPool.DOT_XML;}if (StringUtil.equals(key, "service.java")) {outputPath =serverOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"service" + StringPool.SLASH + "I" + entityName + "Service" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "serviceImpl.java")) {outputPath =serverOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"service" + StringPool.SLASH + "impl" + StringPool.SLASH + entityName + "ServiceImpl" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "entityVO.java")) {outputPath = apiOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"vo" + StringPool.SLASH + entityName + "VO" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "entityDTO.java")) {outputPath = apiOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"dto" + StringPool.SLASH + entityName + "DTO" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "entityExcel.java")) {outputPath = apiOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"excel" + StringPool.SLASH + entityName + "Excel" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "wrapper.java")) {outputPath = apiOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"wrapper" + StringPool.SLASH + entityName + "Wrapper" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "feign.java")) {outputPath = apiOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"feign" + StringPool.SLASH + "I" + entityName + "Client" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "feignclient.java")) {outputPath =serverOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH + "feign"+ StringPool.SLASH + entityName + "Client" + StringPool.DOT_JAVA;}if (StringUtil.equals(key, "feignclientFallback.java")) {outputPath = apiOutputDir + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH +"feign" + StringPool.SLASH + entityName + "ClientFallback" + StringPool.DOT_JAVA;}outputFile(new File(String.valueOf(outputPath)), objectMap, value, Boolean.TRUE);});}/*** 输出实体文件** @param tableInfo 表信息* @param objectMap 渲染数据* @since 3.5.0*/@Overrideprotected void outputEntity(TableInfo tableInfo, Map<String, Object> objectMap) {}/*** 输出Mapper文件(含xml)** @param tableInfo 表信息* @param objectMap 渲染数据* @since 3.5.0*/@Overrideprotected void outputMapper(TableInfo tableInfo, Map<String, Object> objectMap) {}/*** 输出service文件** @param tableInfo 表信息* @param objectMap 渲染数据* @since 3.5.0*/@Overrideprotected void outputService(TableInfo tableInfo, Map<String, Object> objectMap) {}/*** 输出controller文件** @param tableInfo 表信息* @param objectMap 渲染数据* @since 3.5.0*/@Overrideprotected void outputController(TableInfo tableInfo, Map<String, Object> objectMap) {}
}

相关文章:

【java】mybatis-plus代码生成

正常的代码生成这里就不介绍了。旨在记录实现如下功能&#xff1a; 分布式微服务环境下&#xff0c;生成的entity、dto、vo、feignClient等等api模块&#xff0c;需要和mapper、service、controller等等分在不同的目录生成。 为什么会出现这个需求&#xff1f; mybatis-plus&am…...

小样本UIE 信息抽取微调快速上手(不含doccona标注)

文章目录 1.安装环境&#xff08;可略过&#xff09;2.模型简介&#xff08;略读&#xff09;抽取任务输入输出示例&#xff1a;1.实体识别2.关系抽取 3.快速上手(主菜)&#xff08;1&#xff09;转换数据标注数据样例 &#xff08;2&#xff09;生成训练数据训练数据样例 &…...

Vue项目(购物车)

目录 购物车效果展示&#xff1a; 购物车代码&#xff1a; 购物车效果展示&#xff1a; 此项目添加、修改、删除数据的地方都写了浏览器都会把它存储起来 下次运行项目时会把浏览器数据拿出来并在页面展示 Video_20230816145047 购物车代码&#xff1a; 复制完代码&#xff0…...

23.08.16驱动点灯

#include <linux/init.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/uaccess.h> #include <linux/io.h> #include <linux/device.h> #include "head.h"int major; char kbuf[128] {0};//定义指针接收映…...

数据结构——堆

数据结构——堆 堆堆简介堆的分类 二叉堆过程插入操作 删除操作向下调整&#xff1a; 增加某个点的权值实现参考代码&#xff1a;建堆方法一&#xff1a;使用 decreasekey&#xff08;即&#xff0c;向上调整&#xff09;方法二&#xff1a;使用向下调整 应用对顶堆 其他&#…...

重复学习1:NLP

目录 1. 自然语言处理与知识图谱1.1 RNN 循环神经网络初探 2. 吴恩达深度学习 1. 自然语言处理与知识图谱 1.1 RNN 循环神经网络初探 1.1.2 回顾数据维度与神经网络(1) 2. 吴恩达深度学习 P151 1.1 为什么选择序列模型&#xff08;1,2&#xff09; P152 1.2 数学符号(1,)...

做海外游戏推广有哪些条件?

做海外游戏推广需要充分准备和一系列条件的支持。以下是一些关键条件&#xff1a; 市场调研和策略制定&#xff1a;了解目标市场的文化、玩家偏好、竞争格局等是必要的。根据调研结果制定适合的推广策略。 本地化&#xff1a;将游戏内容、界面、语言、货币等进行本地化&#…...

JavaFx基础学习【五】:FXML布局文件使用

目录 前言 一、介绍 二、简单体验 三、FXML标签元素 四、fx属性介绍 五、重写initialize&#xff08;名字需要保持一致&#xff09;方法 六、Scene Builder快速布局 前言 如果你还没有看过前面的文章&#xff0c;可以通过以下链接快速前往学习&#xff1a; JavaFx基础学…...

通过Python爬虫提升网站搜索排名

目录 怎么使用Python爬虫提升排名 1. 抓取竞争对手数据&#xff1a; 2. 关键词研究&#xff1a; 3. 网页内容优化&#xff1a; 4. 内部链接建设&#xff1a; 5. 外部链接建设&#xff1a; 6. 监测和调整&#xff1a; 需要注意哪些方面 1. 合法性和道德性&#xff1a; …...

【博客698】为什么当linux作为router使用时,安装docker后流量转发失败

为什么当linux作为router使用时&#xff0c;安装docker后流量转发失败 场景 当一台linux机器作为其它服务器的router&#xff0c;负责转发流量的时候&#xff0c;让你在linux上安装docker之后&#xff0c;就会出现流量都被drop掉了 原因 没装docker之前&#xff1a; [root~]…...

el-dialog嵌套,修改内层el-dialog样式(自定义样式)

el-dialog嵌套使用时,内层的el-dialog要添加append-to-body属性 给内层的el-dialog添加custom-class属性,添加自定义类名 <el-dialog:visible.sync"dialogVisible"append-to-bodycustom-class"tree-cesium-container"><span>这是一段信息<…...

B树和B+树区别

B树和B树的区别 B树 B树被称为平衡树&#xff0c;在B树中&#xff0c;一个节点可以有两个以上的子节点。B树的高度为log M N。在B树中&#xff0c;数据按照特定的顺序排序&#xff0c;最小值在左侧&#xff0c;最大值在右侧。 B树是一种平衡的多分树&#xff0c;通常我们说m阶…...

intelJ IDEA\PHPStorm \WebStorm\PyCharm 通过ssh连接远程Mysql\Postgresql等数据库

最容易出错的地方是在general面板下的host&#xff0c;不应该填真实的host地址&#xff0c;而应该填localhost或者127.0.0.1 具体操作步骤见下图...

vfuhyuuy

Sublime Text is an awesome text editor. If you’ve never heard of it, you shouldcheck it out right now. I’ve made this tutorial because there’s no installer for the Linux versions of Sublime Text. While that’s not a real problem, I feel there is a clean…...

CSS自学框架之表单

首先我们看一下表单样式&#xff0c;下面共有5张截图 一、CSS代码 /*表单*/fieldset{border: none;margin-bottom: 2em;}fieldset > *{ margin-bottom: 1em }fieldset:last-child{ margin-bottom: 0 }fieldset legend{ margin: 0 0 1em }/* legend标签是CSS中用于定义…...

使用Spring Boot和Redis实现用户IP接口限流的详细指南

系列文章目录 文章目录 系列文章目录前言一、准备工作二、编写限流过滤器三、配置Redis四、测试接口限流总结 前言 在高并发场景下&#xff0c;为了保护系统免受恶意请求的影响&#xff0c;接口限流是一项重要的安全措施。本文将介绍如何使用Spring Boot和Redis来实现用户IP的…...

前端性能优化——包体积压缩插件,打包速度提升插件,提升浏览器响应的速率模式

前端代码优化 –其他的优化可以具体在网上搜索 压缩项目打包后的体积大小、提升打包速度&#xff0c;是前端性能优化中非常重要的环节&#xff0c;结合工作中的实践总结&#xff0c;梳理出一些 常规且有效 的性能优化建议 ue 项目可以通过添加–report命令&#xff1a; "…...

配置vscode

配置vscode 设置相关 网址&#xff1a;https://code.visualstudio.com/ 搜索不要用百度用这个&#xff1a;cn.bing.com 1.安装中文包 Chinese (Simplified) (简体中文) 2.安装 open in browser 3.安装主题 Atom One Dark Theme 4. 安装图标样式 VSCode Great Icons 5.安装 L…...

【Spring】深入理解 Spring 事务及其传播机制

文章目录 一、Spring 事务是什么二、Spring 中事务的实现方法2.1 Spring 编程式事务&#xff08;手动&#xff09;2.1.1 编程式事务的使用演示2.1.2 编程式事务存在的问题 2.2 Spring 声明式事务&#xff08;自动&#xff09;2.2.1 Transactional 作用范围2.2.2 Transactional …...

eclipse常用设置

1、调整编辑页面字体大小 窗口 (Window)- 首选项&#xff08;Preferences&#xff09;- 常规&#xff08;General&#xff09;- 外观 (Appearence)- 颜色与字体 (Colors And Fonts)&#xff0c;在右边的对话框里选择 Java - Java Editor Text Font&#xff0c;点击出现的修改&…...

Redis相关知识总结(缓存雪崩,缓存穿透,缓存击穿,Redis实现分布式锁,如何保持数据库和缓存一致)

文章目录 1.什么是Redis&#xff1f;2.为什么要使用redis作为mysql的缓存&#xff1f;3.什么是缓存雪崩、缓存穿透、缓存击穿&#xff1f;3.1缓存雪崩3.1.1 大量缓存同时过期3.1.2 Redis宕机 3.2 缓存击穿3.3 缓存穿透3.4 总结 4. 数据库和缓存如何保持一致性5. Redis实现分布式…...

反射获取方法和属性

Java反射获取方法 在Java中&#xff0c;反射&#xff08;Reflection&#xff09;是一种强大的机制&#xff0c;允许程序在运行时访问和操作类的内部属性和方法。通过反射&#xff0c;可以动态地创建对象、调用方法、改变属性值&#xff0c;这在很多Java框架中如Spring和Hiberna…...

从零实现STL哈希容器:unordered_map/unordered_set封装详解

本篇文章是对C学习的STL哈希容器自主实现部分的学习分享 希望也能为你带来些帮助~ 那咱们废话不多说&#xff0c;直接开始吧&#xff01; 一、源码结构分析 1. SGISTL30实现剖析 // hash_set核心结构 template <class Value, class HashFcn, ...> class hash_set {ty…...

什么是EULA和DPA

文章目录 EULA&#xff08;End User License Agreement&#xff09;DPA&#xff08;Data Protection Agreement&#xff09;一、定义与背景二、核心内容三、法律效力与责任四、实际应用与意义 EULA&#xff08;End User License Agreement&#xff09; 定义&#xff1a; EULA即…...

C++使用 new 来创建动态数组

问题&#xff1a; 不能使用变量定义数组大小 原因&#xff1a; 这是因为数组在内存中是连续存储的&#xff0c;编译器需要在编译阶段就确定数组的大小&#xff0c;以便正确地分配内存空间。如果允许使用变量来定义数组的大小&#xff0c;那么编译器就无法在编译时确定数组的大…...

2025年渗透测试面试题总结-腾讯[实习]科恩实验室-安全工程师(题目+回答)

安全领域各种资源&#xff0c;学习文档&#xff0c;以及工具分享、前沿信息分享、POC、EXP分享。不定期分享各种好玩的项目及好用的工具&#xff0c;欢迎关注。 目录 腾讯[实习]科恩实验室-安全工程师 一、网络与协议 1. TCP三次握手 2. SYN扫描原理 3. HTTPS证书机制 二…...

逻辑回归暴力训练预测金融欺诈

简述 「使用逻辑回归暴力预测金融欺诈&#xff0c;并不断增加特征维度持续测试」的做法&#xff0c;体现了一种逐步建模与迭代验证的实验思路&#xff0c;在金融欺诈检测中非常有价值&#xff0c;本文作为一篇回顾性记录了早年间公司给某行做反欺诈预测用到的技术和思路。百度…...

在 Spring Boot 项目里,MYSQL中json类型字段使用

前言&#xff1a; 因为程序特殊需求导致&#xff0c;需要mysql数据库存储json类型数据&#xff0c;因此记录一下使用流程 1.java实体中新增字段 private List<User> users 2.增加mybatis-plus注解 TableField(typeHandler FastjsonTypeHandler.class) private Lis…...

通过MicroSip配置自己的freeswitch服务器进行调试记录

之前用docker安装的freeswitch的&#xff0c;启动是正常的&#xff0c; 但用下面的Microsip连接不上 主要原因有可能一下几个 1、通过下面命令可以看 [rootlocalhost default]# docker exec -it freeswitch fs_cli -x "sofia status profile internal"Name …...

消息队列系统设计与实践全解析

文章目录 &#x1f680; 消息队列系统设计与实践全解析&#x1f50d; 一、消息队列选型1.1 业务场景匹配矩阵1.2 吞吐量/延迟/可靠性权衡&#x1f4a1; 权衡决策框架 1.3 运维复杂度评估&#x1f527; 运维成本降低策略 &#x1f3d7;️ 二、典型架构设计2.1 分布式事务最终一致…...