情况是这样的:

原本mybatis-plus的框架的模板是不支持swagger的注解的,需要手动写。

自己折腾了1个多小时,建立在mybatis-plus的基础上进行修改。可以选择生成文件时,不覆盖某个目录下的文件,并支持生成swagger注解。这里把代码贴出来,主要是为了方便以后的兄弟们!!!

需要声明的是,本人的是maven工程,springBoot项目!

工程目录:

GeneratorCodepackage com.asita.renovation;

import com.baomidou.mybatisplus.generator.AutoGenerator;

import com.baomidou.mybatisplus.generator.config.*;

import com.baomidou.mybatisplus.generator.config.rules.DbType;

import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.io.File;

import java.nio.file.Paths;

public class GeneratorCode {

private static String packageName = "com.asita.renovation";

private static String outDir = "F:\\java_web\\renovation\\src\\main\\java";

private static String entity = "entity";

private static String mapper = "mapper";

private static String service = "service";

private static String impl = "service.impl";

private static String controller = "controller";

private static String xml = "mapper.xml";

private static boolean isOverEntity = true;

private static boolean isOverController = false;

private static boolean isOverService = false;

private static boolean isOverServiceImpl = false;

private static boolean isOverMapper = false;

private static boolean isOverXml = false;

private static String entityVM = "/templates/entity.vm";

private static String controllerVM = "/templates/controller.vm";

private static String serviceVM = "";

private static String serviceImplVM = "";

private static String mapperVM = "";

private static String xmlVM = "";

private static String [] baseDir = {entity, mapper, service, impl, controller};

public static void main(String[] args) {

//user -> UserService, 设置成true: user -> IUserService

boolean serviceNameStartWithI = true;

generateByTables(serviceNameStartWithI, packageName,

"bedroom_ratio", "boq", "common_project",

"construction_detail", "construction_detail_item","construction_unit",

"loan_template", "main_material_list", "manager", "material_list",

"material_suppiler_template", "membership_fee",

"room_area_formula", "room_area_formula_template", "toll_switch",

"user", "work_template");

}

private static void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) {

GlobalConfig config = new GlobalConfig();

String dbUrl = "jdbc:mysql://localhost:3306/renovation?serverTimezone=Asia/Shanghai&characterEncoding=utf-8&useSSL=true";

DataSourceConfig dataSourceConfig = new DataSourceConfig();

dataSourceConfig.setDbType(DbType.MYSQL)

.setUrl(dbUrl)

.setUsername("root")

.setPassword("#")

.setDriverName("com.mysql.cj.jdbc.Driver");

StrategyConfig strategyConfig = new StrategyConfig();

strategyConfig

.setCapitalMode(false)

.setEntityLombokModel(true)

.setDbColumnUnderline(true)

.setRestControllerStyle(true)

.entityTableFieldAnnotationEnable(false)

.setNaming(NamingStrategy.underline_to_camel)

//修改替换成你需要的表名,多个表名传数组

.setInclude(tableNames);

config.setActiveRecord(true)

.setAuthor("陈少平")

.setOutputDir(outDir)

.setBaseResultMap(true)

.setBaseColumnList(true)

.setFileOverride(true)

.setEnableCache(false)

// XML ResultMap

.setBaseResultMap(true)

// XML columList;

.setBaseColumnList(true);

if (!serviceNameStartWithI) {

config.setServiceName("%sService");

}

PackageConfig pcf = initPackage();

TemplateConfig tc = initTemplateConfig(packageName);

new AutoGenerator().setGlobalConfig(config)

.setDataSource(dataSourceConfig)

.setStrategy(strategyConfig)

.setPackageInfo(pcf)

.setTemplate(tc)

.execute();

}

/**

* 根据自己的需要,修改哪些包下面的 要覆盖还是不覆盖

* @param packageName

*/

private static TemplateConfig initTemplateConfig(String packageName) {

TemplateConfig tc = new TemplateConfig();

for(String tmp : baseDir) {

initVM(tc);

File file = new File(Paths.get(outDir, String.join("/", packageName.split("\\.")), tmp).toString());

String[] list = file.list();

if(list != null && list.length > 0) {

if(!isOverController) {

tc.setController(null);

}

if(!isOverService) {

tc.setService(null);

}

if(!isOverServiceImpl) {

tc.setServiceImpl(null);

}

if(!isOverEntity) {

tc.setEntity(null);

}

if(!isOverMapper) {

tc.setEntity(null);

}

if(!isOverXml) {

tc.setXml(null);

}

}

}

return tc;

}

private static void initVM(TemplateConfig tc) {

if(stringIsNotNull(entityVM)) {

tc.setEntity(entityVM);

}

if(stringIsNotNull(mapperVM)) {

tc.setMapper(mapperVM);

}

if(stringIsNotNull(serviceImplVM)) {

tc.setServiceImpl(serviceImplVM);

}

if(stringIsNotNull(serviceVM)) {

tc.setService(serviceVM);

}

if(stringIsNotNull(xmlVM)) {

tc.setXml(xmlVM);

}

if(stringIsNotNull(controllerVM)) {

tc.setController(controllerVM);

}

}

/**

* 简单判断字符串是不是为空

* @param s

* @return

*/

private static boolean stringIsNotNull(String s) {

if(null != s && !s.equals("") && s.length() > 0 && s.trim().length() > 0) {

return true;

}

return false;

**加粗文字** }

/**

* 初始化包目录配置

* @return

*/

private static PackageConfig initPackage() {

PackageConfig packageConfig = new PackageConfig();

packageConfig.setParent(packageName);

packageConfig.setService(service);

packageConfig.setServiceImpl(impl);

packageConfig.setController(controller);

packageConfig.setEntity(entity);

packageConfig.setXml(xml);

return packageConfig;

}

}

/templates/controller.vmpackage ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;

import io.swagger.annotations.Api;

#if(${restControllerStyle})

import org.springframework.web.bind.annotation.RestController;

#else

import org.springframework.stereotype.Controller;

#end

#if(${superControllerClassPackage})

import ${superControllerClassPackage};

#end

/**

* @author ${author}

* @since ${date}

*/

@Api(tags = {"$!{table.comment}"})

#if(${restControllerStyle})

@RestController

#else

@Controller

#end

@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")

#if(${kotlin})

class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end

#else

#if(${superControllerClass})

public class ${table.controllerName} extends ${superControllerClass} {

#else

public class ${table.controllerName} {

#end

}

#end

/templates/entity.vmpackage ${package.Entity};

#foreach($pkg in ${table.importPackages})

import ${pkg};

#end

#if(${entityLombokModel})

import io.swagger.annotations.ApiModel;

import io.swagger.annotations.ApiModelProperty;

import lombok.Data;

import lombok.EqualsAndHashCode;

import lombok.experimental.Accessors;

#end

/**

* @author ${author}

* @since ${date}

*/

@ApiModel(value ="$!{table.comment}")

#if(${entityLombokModel})

@Data

#if(${superEntityClass})

@EqualsAndHashCode(callSuper = true)

#else

@EqualsAndHashCode(callSuper = false)

#end

@Accessors(chain = true)

#end

#if(${table.convert})

@TableName("${table.name}")

#end

#if(${superEntityClass})

public class ${entity} extends ${superEntityClass}#if(${activeRecord})#end {

#elseif(${activeRecord})

public class ${entity} extends Model {

#else

public class ${entity} implements Serializable {

#end

private static final long serialVersionUID = 1L;

## ---------- BEGIN 字段循环遍历 ----------

#foreach($field in ${table.fields})

#if(${field.keyFlag})

#set($keyPropertyName=${field.propertyName})

#end

#if("$!field.comment" != "")

@ApiModelProperty(value = "${field.comment}")

#end

#if(${field.keyFlag})

## 主键

#if(${field.keyIdentityFlag})

@TableId(value = "${field.name}", type = IdType.AUTO)

#elseif(!$null.isNull(${idType}) && "$!idType" != "")

@TableId(value = "${field.name}", type = IdType.${idType})

#elseif(${field.convert})

@TableId("${field.name}")

#end

## 普通字段

#elseif(${field.fill})

## ----- 存在字段填充设置 -----

#if(${field.convert})

@TableField(value = "${field.name}", fill = FieldFill.${field.fill})

#else

@TableField(fill = FieldFill.${field.fill})

#end

#elseif(${field.convert})

@TableField("${field.name}")

#end

## 乐观锁注解

#if(${versionFieldName}==${field.name})

@Version

#end

## 逻辑删除注解

#if(${logicDeleteFieldName}==${field.name})

@TableLogic

#end

private ${field.propertyType} ${field.propertyName};

#end

## ---------- END 字段循环遍历 ----------

#if(!${entityLombokModel})

#foreach($field in ${table.fields})

#if(${field.propertyType.equals("boolean")})

#set($getprefix="is")

#else

#set($getprefix="get")

#end

public ${field.propertyType} ${getprefix}${field.capitalName}() {

return ${field.propertyName};

}

#if(${entityBuilderModel})

public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {

#else

public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {

#end

this.${field.propertyName} = ${field.propertyName};

#if(${entityBuilderModel})

return this;

#end

}

#end

#end

#if(${entityColumnConstant})

#foreach($field in ${table.fields})

public static final String ${field.name.toUpperCase()} = "${field.name}";

#end

#end

#if(${activeRecord})

@Override

protected Serializable pkVal() {

#if(${keyPropertyName})

return this.${keyPropertyName};

#else

return null;

#end

}

#end

#if(!${entityLombokModel})

@Override

public String toString() {

return "${entity}{" +

#foreach($field in ${table.fields})

#if($!{velocityCount}==1)

"${field.propertyName}=" + ${field.propertyName} +

#else

", ${field.propertyName}=" + ${field.propertyName} +

#end

#end

"}";

}

#end

}

附上maven的配置,以及springBoot 的配置

com.baomidou

mybatisplus-spring-boot-starter

1.0.5

com.baomidou

mybatis-plus

2.3

org.apache.velocity

velocity-engine-core

2.0

io.springfox

springfox-swagger2

2.8.0

io.springfox

springfox-swagger-ui

2.8.0

mybatis-plus:

mapper-locations: classpath:/com/asita/renovation/mapper/xml/*Mapper.xml

typeAliasesPackage: com.asita.renovation.entity

global-config:

#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";

id-type: 0

#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"

field-strategy: 2

#刷新mapper 调试神器

refresh-mapper: true

#驼峰下划线转换

# db-column-underline: true

# Sequence序列接口实现类配置

key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator

configuration:

map-underscore-to-camel-case: true

cache-enabled: false

相关文章:

java 生成并覆盖文件,基于mybatis-plus生成不被覆盖的文件并支持swagger注解相关推荐

  1. java rnn生成古诗_Tensorflow:基于LSTM轻松生成各种古诗

    原标题:Tensorflow:基于LSTM轻松生成各种古诗 本文代码在公众号 datadw 里 回复古诗即可获取. RNN不像传统的神经网络-它们的输出输出是固定的,而RNN允许我们输入输出向量序列. ...

  2. lisp自动生成界址点表_基于AutoCAD VBA增减挂钩报备坐标文件自动生成.doc

    基于AutoCAD VBA增减挂钩报备坐标文件自动生成 基于AutoCAD VBA增减挂钩报备坐标文件自动生成 摘要:生成增减挂钩报备坐标文件是一项非常繁琐的工作,会占用大量工作时间.如果利用VBA对 ...

  3. DM8(达梦数据库)基于建库SQL生成ER图,基于ER图生成数据库文档

    今天项目经理让我导出DM8 数据库说明文档,我立刻想到了数据库文档生成工具(screw-钉子),我立刻添加相关maven 依赖,编写junit 单元代码.但是执行的结果让我很沮丧. 相关依赖和Juni ...

  4. 【优化覆盖】基于matlab果蝇算法求解无线传感器覆盖优化问题【含Matlab源码 2215期】

    一.⛄果蝇算法 果蝇优化算法(Fruit Fly Optimization Algorithm, FOA) 是台湾学者潘文超经过研究发现, 并于2011年提出的一种新型智能优化算法, 它具有很好的全局 ...

  5. 基于用户喜爱生成推荐电影

    基于用户喜爱生成推荐电影 目录 基于用户喜爱生成推荐电影 集合说明 代码描述 代码 总结 集合说明 用户集:该集合是通过代码生成 电影集:kaggle.com上面的数据集,filmtv_movies ...

  6. python全唐诗json文件基于作者姓名检索--以李白为例

    python全唐诗json文件基于作者姓名检索--以李白为例 文件来源 单个文本分析 对全唐诗json文件进行整体分析 全部代码展示 因为是边做边写的博客,文中我发现我的文学水平急待加强! 全唐诗竟然 ...

  7. 自动生成Mapper文件(基于Mybatis Maven插件)

    自动生成Mybatis的Mapper文件 工作中使用mybatis时我们需要根据数据表字段创建pojo类.mapper文件以及dao类,并且需要配置它们之间的依赖关系,这样的工作很琐碎和重复,myba ...

  8. 使用maven工程实现Mybatis自动生成Mapper文件

    本文档为学习记录,参考博文: https://www.cnblogs.com/handsomeye/p/6268513.html https://www.cnblogs.com/maanshancss ...

  9. java生成iso9660工具_基于数据库的代码自动生成工具,生成JavaBean、生成数据库文档、生成前后端代码等(TableGo v7.0.0版)...

    TableGo_20210212 v7.0.0 正式版发布,此次版本更新如下: 1.新增对DB2数据库的支持 2.新增按字段生成文件,支持把字段.JSON.XML数据转换成任何代码 3.新增大量新的自 ...

最新文章

  1. 台式计算机m9870t,JBT9870_水力测功器最新标准规范(14页)-原创力文档
  2. SAP SOAMANAGER报错原因与故障排除方法
  3. Hibernate中的JPA 2.1条件删除/更新和临时表
  4. vps没有mysql怎么用商店_如何在本地搞一个小程序的服务器之我没有vps我也很绝望呀...
  5. 基于java的邮件服务器以及webmail的搭建
  6. Win10下NTFS分区变RAW修复的一种错误方法
  7. 眼镜寿命不仅跟镜架材质有关,还跟习惯有关系!
  8. INS 图片/视频保存
  9. 2015上半年教师资格考试高中数学(404)- 用向量数量积推导两角差余弦公式
  10. BZOJ2959长跑——LCT+并查集(LCT动态维护边双连通分量)
  11. PWN之堆利用-unlink攻击
  12. 【机器学习|数学基础】Mathematics for Machine Learning系列之图论(8):割边、割集、割点
  13. Markdown 文本编辑图片居中显示以及题注
  14. 8021什么意思_ox004a8021 指令引用的 0x01ac1100内存 是什么意思?
  15. 常用dos命令(五)--DEL和ERASE命令
  16. Java学习第七天 ———— 第一周学习汇总(粗略)
  17. ROS从入门到精通0-2:Win10+Ubuntu双系统安装、配置、卸载保姆级图文教程
  18. 中国志愿者服务器注册,中国志愿者服务网注册平台登录入口:http://www.chinavolunteer.cn/...
  19. JAVA设计模式什么鬼(门面)——作者:凸凹里歐
  20. 将每个幻灯片顶部的标题设置动画_如何设置第一张幻灯片中的标题动画为螺旋,声音为风铃声。副标题为上部飞入?...

热门文章

  1. 需要氪金吗_《天堂2:血盟》到底需不需要氪金?玩家:可以但是没有必要
  2. python tcp服务器 多线程_Python中的多线程TCP服务器
  3. fabric go sdk 依赖的安装_从这些角度看 Go 是一门很棒的语言
  4. linux怎么测试磁盘读写,怎样测试Linux磁盘的读写速率
  5. Jmeter性能测试之if控制器的使用
  6. CentOS6.3环境下openresty安装drizzle模块
  7. 好的视频编解码网址和博文地址
  8. mysql创建用户并授登录权限_mysql创建用户并授予权限
  9. 镜像和linux关系,Docker中容器和镜像的关系【通俗易懂】
  10. matlab哈明窗带阻,数字信号处理实验1,2,3,4