在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>