To implement dynamic incoming table names and column names, you need to make the following modifications
- Add Property statementtype= "STATEMENT"
- At the same time, the value of the genus variable in SQL is changed to ${xxxx} instead of #{xxx}
<id= "Deletetabledata" parametertype= "Java.util.Map" StatementType= "STATEMENT"> <![ cdata[ Delete from ${table} where ${col} < ${date}]]></ Delete>
1. Statementtype:statement (non-precompiled), PREPARED (precompiled) or any of the callable, which tells MyBatis to use STATEMENT respectively, PreparedStatement or CallableStatement. Default:
PREPARED. It is obviously not possible to use precompilation and to change to non-precompiled.
2. ${xxxx}:$ generates the incoming data directly in SQL and requires manual quotation marks for string data.
String datestr = Dateformatutils.format (Date.gettime (), "Yyyy-mm-dd HH:mm:ss");
Description
StatementType: The function of this property is to tell MyBatis whether the SQL we wrote is precompiled (Prestatement) or non-precompiled (STATEMENT). What difference does it have? If it is precompiled, then the system reads the SQL code at initialization, replacing the fields in the specified entity class with statements like #{}, which is a statement like this:
"SELECT * from TableName where code=?" This time when you are running the system and want to replace the SQL TableName or code, the results can be imagined. If it is non-precompiled, the result is just the opposite, and he will generate a similar statement when the system is running. You can now replace these dynamic fields or table names.
MyBatis dynamic Incoming table name, field name parameter resolution