MyBatis Generator配置文件--指定生成实体类的属性名

2023-05-16

table标签下的设置属性useActualColumnNames用于指定生成实体类时是否使用实际的列名作为实体类的属性名,取值true或false。
true:MyBatis Generator会使用数据库中实际的字段名字作为生成的实体类的属性名。

false:这是默认值。如果设置为false,则MyBatis Generator会将数据库中实际的字段名字转换为Camel Case风格作为生成的实体类的属性名。

如果明确的使用columnOverride元素指定了字段对应的实体的属性名,那么useActualColumnNames会被忽略。
例:

<table tableName="v_user_detail" domainObjectName="VUserDetail"
       enableCountByExample="false" enableUpdateByExample="false"
       enableDeleteByExample="false" enableSelectByExample="false"
       selectByExampleQueryId="false" enableInsert="false"
       enableSelectByPrimaryKey="true" selectByPrimaryKeyQueryId="true">
      <property name="useActualColumnNames" value="true"/>
</table>

如果需要自行指定数据库与实体类的对应字段,可以使用 columnOverride
例:

<table tableName="v_user_detail" domainObjectName="VUserDetail"
       enableCountByExample="false" enableUpdateByExample="false"
       enableDeleteByExample="false" enableSelectByExample="false"
       selectByExampleQueryId="false" enableInsert="false"
       enableSelectByPrimaryKey="true" selectByPrimaryKeyQueryId="true">
       <columnOverride column="userid" property="userId" javaType="java.lang.Integer" jdbcType="INTEGER" />
       <columnOverride column="createtime" property="createTime"/>
       <columnOverride column="updatetime" property="updateTime"/>
</table>

columnOverride也可以针对字段类型为text等会默认产生XXXXWithBlobs的方法问题

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MyBatis Generator配置文件--指定生成实体类的属性名 的相关文章

随机推荐