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的方法问题
MyBatisGenerator配置详解
本文详细解析了MyBatisGenerator中的useActualColumnNames属性作用,介绍了如何通过该属性控制实体类属性名的生成方式,并展示了如何使用columnOverride元素自定义数据库字段与实体类属性的映射。

1万+

被折叠的 条评论
为什么被折叠?



