MyBatis dynamic Incoming table name, field name parameter resolution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.