• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

mybatis-generator-xplugin: mybatis-generator常用插件,持续更新

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

mybatis-generator-xplugin

开源软件地址:

https://gitee.com/trytotry/mybatis-generator-xplugin

开源软件介绍:

mybatis-generator-xplugin

收集了很多mybatis-generator的插件,都是自己项目中用到的,为了方面使用,会上传到中心maven库,凡是用了其他人的插件,都会说明,如有冒犯,请告知,立马删除。邮箱:[email protected]

当初就是因为引用不方便,所以建了这个工程,集合了很多好用的插件,当前版本0.0.1

<dependency>    <groupId>com.trytotry</groupId>    <artifactId>mybatis-generator-xplugin</artifactId>    <version>0.0.1</version></dependency>

OverIsMergeablePlugin

在生产xml文件的时候,默认会追加方法,而不会覆盖重写,找了很多方法,终于找到这个有用的,谢谢作者
原作者地址:https://my.oschina.net/u/137785/blog/736372
引入插件

<plugin type="com.trytotry.mybatis.generator.plugin.OverIsMergeablePlugin"/>

SelectByColumnPlugin

自己写的方法,会生成selectByxxx的方法,方便查询引入插件

<plugin type="com.trytotry.mybatis.generator.plugin.SelectByColumnPlugin"/>

config中配置

<table tableName="test">    <property name="selectBy" value="name"/></table>

则对应TestMapper中生产方法

List<Test> selectByName(String name);

ModelEqualsPlugin

自己写的插件,在model中生成equals的重载方法,方便判断引入插件:

<plugin type="com.trytotry.mybatis.generator.plugin.ModelEqualsPlugin"/>

config中配置,此时,equals将会判断字段id和name是否相等,相等则return true

<table tableName="test">    <property name="equalsValue" value="id,name"/></table>

MySqlUpsertPlugin

生成upsert方法原作者地址:https://github.com/beihaifeiwu/dolphin引入插件(保留原作者包名)

<plugin type="com.freetmp.mbg.plugin.upsert.MySqlUpsertPlugin"/>

Java Sample

Test test = new Test().setId(2).setName("123").setPrice(123d);mapper.upsert(test);

对应生产sql

INSERT INTO test (id, NAME, price)    VALUES (2, '123', 123) ON DUPLICATE KEY     UPDATE id = 1,	NAME = '123',	price = 123

MinMaxPlugin

在mapper中增加min和max方法原作者地址:https://github.com/oceanc/mybatis3-generator-plugins引入插件(保留原作者包名)

<plugin type="com.github.oceanc.mybatis3.generator.plugin.MinMaxPlugin"/>

config中配置

<table tableName="test">    <property name="minColumns" value="id,price"/>    <property name="maxColumns" value="id,price"/></table>

则对应生产Java代码

mapper.maxIdByExample(example);mapper.minIdByExample(example);mapper.maxPriceByExample(example);mapper.minPriceByExample(example);

SumSelectivePlugin

sum插件原作者地址:https://github.com/oceanc/mybatis3-generator-plugins引入插件(保留原作者包名)

<plugin type="com.github.oceanc.mybatis3.generator.plugin.SumSelectivePlugin"/><plugin type="com.github.oceanc.mybatis3.generator.plugin.WhereSqlTextPlugin"/><plugin type="xyz.vsl.mybatis.generator.pluginsplus.ModelSettersChainPlugin"/>

则对应生产Java代码

example.sumPrice(); //注意要添加sum的字段mapper.sumByExample(example);

WhereSqlTextPlugin

自定义sql插件原作者地址:https://github.com/oceanc/mybatis3-generator-plugins引入插件(保留原作者包名)

<plugin type="com.github.oceanc.mybatis3.generator.plugin.WhereSqlTextPlugin"/><plugin type="xyz.vsl.mybatis.generator.pluginsplus.ModelSettersChainPlugin"/>

则对应生产Java代码,addConditionSql中可以自定义sql

example.createCriteria().andIdEqualTo(1).addConditionSql("1=1");

ModelSettersChainPlugin

model层可以连续set的插件原作者地址:https://github.com/vsl1978/mybatis-generator-pluginsplus引入插件(保留原作者包名)

<plugin type="xyz.vsl.mybatis.generator.pluginsplus.ModelSettersChainPlugin"/>

则对应生产Java代码,你可以这样写

Test test = new Test().setId(2).setName("123").setPrice(123d);mapper.upsert(test);

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap