在mysql中构建user等不同数据库同名表时出现的问题,关键是两点:
- catalog字段来加入数据库名称, 区分不同数据库的同名表;
- 使用ignoreQualifiersAtRuntime来忽略前缀;
如果是需要返回自动产生的id,则需要加入generatedKey。
generatorConfig.xml中table段的代码如下:
<table catalog="wms" tableName="user">
<!--默认为false,如果设置为true,在生成的SQL中,table名字不会加上catalog或schema-->
<property name="ignoreQualifiersAtRuntime" value="true"/>
<!-- 插入一条数据到数据库之后,能从当前这个Entity中获取到插入之后的Id -->
<!-- <generatedKey column="ID" sqlStatement="Mysql" identity="true"/> -->
</table>