有时候我们在定义数据库字段的时候,需要加一些前缀说明字段的类型,如S_NAME、L_OBJID、N_ID等,在使用mybatis-generator生成实体成员的时候默认会生成sName,lObjid。但是是实际上s或者l在实体中没有意义,我们需要去掉这些前缀。
研究mybatis-generator源码的时候,发现在生成实体成员名称的地方其实可以使用正则表达式自定义名称:
这个配置在generatorConfig.xml添加即可,通过正则表达式替换前缀。
<table tableName="T_MYBATIS"
enableCountByExample="true"
enableUpdateByExample="true"
enableDeleteByExample="true"
enableSelectByExample="true"
selectByExampleQueryId="true">
<columnRenamingRule searchString="^[A-Z]_" replaceString=""></columnRenamingRule>
</table>