目前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 啦