Mybatis dynamic table name + Map parameter transfer + batch operation

Requirement: For a change in the previous project, it is necessary to clean the data of 3 mysql database tables. The table names of the 3 tables are different, and the table structure is exactly the same. It is necessary to perform the same actions of adding, modifying, and checking these 3 tables, which is urgent at the beginning. First operate on a table, and then copy three identical services, dao, mapper, etc. Later, the code was optimized, and the processing of dynamic table names was studied.
1. Query operation:
  • When the query operation only needs to pass in the dynamic table name, the passed parameter is still map
  • In mapper.xml, you need to use statementType="STATEMENT" and use non-precompiled mode
  • In mapper.xml, the dynamic table name is obtained using ${tableName}

2. Batch insert operation:
  • When the query operation only needs to pass in the dynamic table name, the passed parameter is still map
  • In mapper.xml, there is no need to use statementType="STATEMENT", otherwise, an error will be prompted at runtime (the specific reason is not very clear).
  • The dynamic table name is obtained by using ${tableName}, and the collection attribute of insert is named as the key name in the map of the incoming parameter, without any modifier.
  • Use #{item.guid} to get list content, not $.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324517817&siteId=291194637