引言

mybatis-generator-maven-plugin、MyBatisPlus 对比。

1、mybatis-generator-maven-plugin插件深度更深,对mybatis提供的操作更仔细,不仅有简单的增删改查,还可以动态的使用where语句来操作。

2、MyBatisPlus插件主要提供了一些模板来操作,主要的模板有:velocity 模板引擎, 默认、freemarker 模板引擎、beetl 模板引擎等。生成一些常用的基于sql自动生成domain、controller、service、dao、mapper,只是框架模型,具体操作很少。

mybatis-generator-maven-plugin

官方文档:http://www.mybatis.org/generator/index.html

1、pom.xml中要引入的jar包

<!-- mybatis--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.1</version></dependency>    <dependency><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-core</artifactId><version>1.3.7</version></dependency>       <build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><!-- mybatis generator 自动生成代码插件 --><plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>1.3.7</version><configuration><configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile><!-- 是否覆盖 --><overwrite>true</overwrite><!--允许移动生成的文件 --><verbose>true</verbose></configuration><dependencies><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.6</version></dependency><!--集成gen使用的通用mapper依赖--><dependency><groupId>tk.mybatis</groupId><artifactId>mapper</artifactId><version>4.1.5</version></dependency></dependencies></plugin></plugins></build>

2.配置默认文件 generatorConfig.xml 此文件放置在 src/main/resources 下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><!-- mybatis-generator-maven-plugin插件配置-->
<generatorConfiguration><!-- 导入配置文件 --><!-- <properties resource="application.yml"/>--><!-- defaultModelType="flat" 设置复合主键时不单独为主键创建实体 --><!--<context id="MySql" defaultModelType="flat">--><!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包--><classPathEntry  location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar"/><context id="DB2Tables"  targetRuntime="MyBatis3"><!-- 自动识别数据库关键字,默认false,如果设置为true,根据SqlReservedWords中定义的关键字列表;一般保留默认值,遇到数据库关键字(Java关键字),使用columnOverride覆盖--><property name="autoDelimitKeywords" value="false"/><!-- 生成的Java文件的编码 --><property name="javaFileEncoding" value="UTF-8"/><!-- 格式化java代码 --><property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/><!-- 格式化XML代码 --><property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/><!-- 生成的pojo,将implements Serializable --><plugin type="org.mybatis.generator.plugins.SerializablePlugin"/><!--生成的java对象模型自动添加hashCode()和Equals()方法--><plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"/><!--生成的java对象模型自动添加toString()方法--><plugin type="org.mybatis.generator.plugins.ToStringPlugin"/><!--直接生成映射注解--><plugin type="org.mybatis.generator.plugins.MapperAnnotationPlugin"/><!--开启支持内存分页   可生成 支持内存分布的方法及参数--><plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"/><!--下面的插件需要把插件的jar包自己手动添加在本地mven环境中--><!--使用自定义的分页插件需要搭乘jar包在,安装到仓库,在导入pom.xml中使用 --><!-- 批量插入插件 --><!-- <plugin type="com.itfsw.mybatis.generator.plugins.BatchInsertPlugin">&lt;!&ndash;开启后可以实现官方插件根据属性是否为空决定是否插入该字段功能!需开启allowMultiQueries=true多条sql提交操作,所以不建议使用!插件默认不开启&ndash;&gt;<property name="allowMultiQueries" value="false"/></plugin>--><!--批量更新--><!--<plugin type="cc.bandaotixi.plugins.BatchUpdatePlugin"/>--><!-- 生成一对一配置 --><!--<plugin type="cc.bandaotixi.plugins.OneToOnePlugin"/>--><!-- 生成一对多配置 --><!--<plugin type="cc.bandaotixi.plugins.OneToManyPlugin"/>--><plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin"><property name="searchString" value="Example$" /><property name="replaceString" value="Criteria" /></plugin><commentGenerator><!-- 将数据库中表的字段描述信息添加到注释 --><property name="addRemarkComments" value="true"/><!-- 注释里不添加日期 --><property name="suppressDate" value="true"/><!-- 是否去除自动生成的注释 true:是 : false:否 --><property name="suppressAllComments" value="false"/></commentGenerator><!--数据库链接URL,用户名、密码 --><!-- 数据库连接,直接通过${}读取application.properties里的配置 --><jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.0.18/meter_basis" userId="root" password="root"></jdbcConnection><!-- <jdbcConnectiondriverClass="${spring.datasource.druid.driver-class-name}"connectionURL="${spring.datasource.druid.url}"userId="${spring.datasource.druid.username}"password="${spring.datasource.druid.password}"></jdbcConnection>--><javaTypeResolver><property name="forceBigDecimals" value="false"/></javaTypeResolver><!-- 生成生成POJO对象模型的包名和位置--><javaModelGenerator targetPackage="com.kmnfsw.generator.domain" targetProject="src/main/java"><!-- 在targetPackage的基础上,根据数据库的schema再生成一层package,最终生成的类放在这个package下,默认为false --><property name="enableSubPackages" value="true"/><!-- 设置是否在getter方法中,对String类型字段调用trim()方法 --><property name="trimStrings" value="true"/><!--  for MyBatis3/MyBatis3Simple自动为每一个生成的类创建一个构造方法,构造方法包含了所有的field;而不是使用setter; --><property name="constructorBased" value="false"/></javaModelGenerator><!-- 生成mapper xml映射文件的包名和位置--><sqlMapGenerator targetPackage="generator/mapper" targetProject="src/main/resources"><property name="enableSubPackages" value="true"/></sqlMapGenerator><!-- 生成DAO的包名和位置--><javaClientGenerator type="XMLMAPPER" targetPackage="com.kmnfsw.generator.dao" targetProject="src/main/java"><property name="enableSubPackages" value="true"/></javaClientGenerator><!-- table标签可以有多个,至少一个,tableName指定表名,可以使用_和%通配符 --><!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--><table tableName="channel_early_warning_type" domainObjectName="ChannelEarlyWarningtType" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="channel_info" domainObjectName="ChannelInfo" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="channel_link_notice" domainObjectName="ChannelLinkNotice" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="channel_range_early_warning" domainObjectName="ChannelRangeEarlyWarning" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="channel_switch_early_warning" domainObjectName="ChannelSwitchEarlyWarning" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="channel_value_early_warning" domainObjectName="ChannelValueEarlyWarning" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="device_info" domainObjectName="DeviceInfo" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="equipment_info" domainObjectName="EquipmentInfo" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="group_link_notice" domainObjectName="GroupLinkNotice" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="inform_person_group_info" domainObjectName="InformPersonGroupInfo" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="meter_info" domainObjectName="MeterInfo" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table><table tableName="tag_group_info" domainObjectName="TagGroupInfo" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table></context>
</generatorConfiguration>

4、在mevn中直接执行即可

MyBatisPlus 

这个插件的使用直接看这些篇博客即可,已测试,可以生成。

https://www.cnblogs.com/douJiangYouTiao888/p/9266727.html

https://blog.csdn.net/Neal_/article/details/86030791

官方文档:https://mp.baomidou.com/config/generator-config.html

java代码mybatis代码生成器插件相关推荐

  1. Vim中的Java代码补全插件

    Vim中的Java代码补全插件 最近在学习用vim写Java代码,用惯了idea,发现vim也太简陋了.后来在网上搜,看到不少文章介绍这个Javacomplete : Omni Completion ...

  2. VSCode Java 代码补全插件

    新装的VSCode写一个Java文件竟然没有代码自动补全,下载了以下插件Java Extension Pack: 插件链接:https://marketplace.visualstudio.com/i ...

  3. Java代码规范检查插件调研及总结

    代码规范工具对比 代码规范工具是什么 大家应该都有过写完代码后review的情况:用于提高编码质量,尽早的发现问题:节约开发时间和成本. 但review 这个过程往往要消耗 更多的开发资源. 所以就出 ...

  4. IDEAL葵花宝典:java代码开发规范插件 FindBugs-IDEA

     前言: 检测代码中可能的bug及不规范的位置,检测的模式相比p3c更多,写完代码后检测下 避免低级bug,强烈建议用一下,一不小心就发现很多老代码的bug. 使用步骤: 1):打开 Settings ...

  5. java json插件安装_IDEAL葵花宝典:java代码开发规范插件:GsonFormat插件将JSONObject格式的String 解析成实体...

    前言: GsonFormat插件主要用于使用Gson库将JSONObject格式的String 解析成实体,该插件可以加快开发进度,使用非常方便,效率高. 这个教程主要是学习IntelliJ IDEA ...

  6. 安装阿里Java代码规约插件

    概述 2017年10月14日杭州云栖大会,Java代码规约扫描插件全球首发仪式正式启动,规范正式以插件形式公开走向业界,引领Java语言的规范之路.目前,插件已在云效公有云产品中集成,立即体验!(云效 ...

  7. Protobuf生成Java代码(Maven)

    1.说明 本文介绍Protobuf生成Java代码的方法, 配置对应的Maven插件, 把.proto文件生成Java代码. 2.插件配置 创建Maven工程grpc-compile, 修改pom.x ...

  8. MyBatis代码生成器Gradle插件分享

    这是一个MyBatis代码的代码生成器.阅读本文或使用本文代码可能需要一定的Gradle技术基础. 现在使用Gradle来管理的项目越来越多,这个使用Gradle操作的代码生成器插件写了很久了,最近整 ...

  9. java delegate怎么写_美团面试官:你说你们公司的Mybatis分页插件是你写的,给我说说它的设计原理?...

    来源:http://my.oschina.net/zudajun 大多数框架,都支持插件,用户可通过编写插件来自行扩展功能,Mybatis也不例外. 我们从插件配置.插件编写.插件运行原理.插件注册与 ...

最新文章

  1. Could not initialize class org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImplKt
  2. v9php 碎片信息,phpcms v9碎片管理及调用技巧分享
  3. scrapy中的request对象
  4. 还在重复造轮子?Java开发人员必知必会的20种常用类库和API
  5. Android SQLite Database的使用模板
  6. html多重边框,中间空白,CSS实现多重边框
  7. python的字典与集合
  8. C51语言支持哪些数据类型,C51编译器支持的数据类型(1)
  9. python中argv的用法
  10. Diffie Hellman密钥交换
  11. 1086: [SCOI2005]王室联邦
  12. SAP License:如何做好ERP系统验收测试
  13. 要获取NAT之后的外网IP地址
  14. 苹果之父乔布斯:我是如何东山再起的
  15. C#反射技术的简单操作(读取和设置类的属性)
  16. 区县级应急综合管理系统功能
  17. 第7章第25节:双图排版:两张图片横竖交错叠加排版 [PowerPoint精美幻灯片实战教程]
  18. C++ 使用chrono库准确统计代码运行时间
  19. mysql show slave status 无记录_从show slave status 中判断mysql同步状态
  20. html实现播放器下一集方法,本地化DPLAYER和CKPLAYER播放器自动下一集

热门文章

  1. linux(ubuntu)系统下Top命令详解
  2. mac/win的Qt::ControlModifier以及如何输出mac平台的修饰符符号?
  3. 解决EXP-00079: 表 PURCHASEORDER 中的数据是被保护的。常规路径只能导出部分表。
  4. mysql 创建覆盖索引_MySql覆盖索引
  5. 微信支付——扫码支付Native
  6. 中国移动将于3月31日发布2018年全年财报
  7. php 不重复订单号,php如何生成不重复的订单号
  8. hcq0-1100-d
  9. AxureRP8实战手册-案例27(字符串函数:手机号码验证①)
  10. <数据结构>折半查找算法实现