41

MyBatis Generator配置文件--指定生成实体类使用实际的表列名作为实体类的属性名

 4 years ago
source link: https://www.ydstudio.net/archives/146.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

今天在用MyBatis Generator生成表实体的时候,发现数据库中的表字段使用的是小驼峰命名规则,生成出来的实体属性都是小写了,没有转成小驼峰,一番搜索得知可以在MyBatis Generator的配置文件中修改。

table标签下的设置属性useActualColumnNames用于指定生成实体类时是否使用实际的列名作为实体类的属性名,取值true或false。

true:MyBatis Generator会使用数据库中实际的字段名字作为生成的实体类的属性名。

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

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

假设表有一个字段名为start_date,如果这个属性设置为true,则生成的实体类的属性名为start_date,生成的setter/getter为setStart_date/getStart_date。如果useActualColumnNames设置为false,则生成的实体类的属性名为startDate,生成的setter/getter为setStartDate/getStartDate。

<table tableName="dobbo_goods_order" domainObjectName="GoodsOrder" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" >
            <!-- table标签下的设置属性useActualColumnNames用于指定生成实体类时是否使用实际的列名作为实体类的属性名,取值true或false-->
            <property name="useActualColumnNames" value="true" />
        </table>

最后更新于 2019-05-13 17:52:13 并被添加「java mybatis」标签,已有 4 位童鞋阅读过。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK