mybatis-generator指定列进行自动生成代码

目前mybatis-generator已经升级到1.3.3,功能比较强大,但是目前从table中如果字段较多可以选择忽略生产的字段(通过ignoreColumn属性实现,http://generator.sturgeon.mopaas.com/configreference/ignoreColumn.html),如果一个table字段太多而只需要某几个字段,例如100个字段的表格中只要5个,

那么需要选择95个字段进行ignore,这样费时也费神,而且极容易出错,想想如果copy到第90个字段的时候,你的小伙伴往数据库插入了一个字段,于是你弄完95个字段后,兴致勃勃生成了代码.

测试环境一切正常,到了线上可能就报错了,那一个字段线上还没有.

基于此问题,如果可以支持指定字段生成就完美了.于是对源码进行了一定程度的修改.

github:https://github.com/candyleer/generator/tree/feature/candylee_requiredcolum

可以在配置文件进行如下配置,便可以只生成指定字段.

<table tableName="brands" domainObjectName="Brand" alias="b">
       <requiredColumn column="title"/>
        <requiredColumn column="hot"/>
 </table>

 ps:官方版本从1.3.4开始,支持此属性的配置,配置略有不同,配置如下:

http://www.mybatis.org/generator/configreference/ignoreColumnsByRegex.html

Example
This example tells MyBatis to ignore every column in the Foo table that begins with the characters "col" (case-insensitive) except for "col01" and "col13".

    <table tableName="Foo">
      <ignoreColumnsByRegex pattern="(?i)col.*">
        <except column="col01"/>
        <except column="col13"/>
      </ignoreColumnsByRegex>
    </table>

可以使用官方配置,不用写诸多的ignore 啦

转载于:https://my.oschina.net/u/3252507/blog/836103

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值