MyBatis is parsed Using Dynamic tables or column code, and mybatis is dynamic

Source: Internet
Author: User

MyBatis is parsed Using Dynamic tables or column code, and mybatis is dynamic

Sometimes it is inevitable to use dynamic tables or columns for business processing. The following describes how to use dynamic tables/columns:

[1] use pre-Compilation

That is, the default value.

<Select id = "hisNumber" parameterType = "hashmap" resultType = "hashmap"> select number from $ {oldTableName} <! -- Use "$" here "!!! --> Where name = # {name} and date = # {date} <! -- Use "#" --> <select>

Pre-compile: select number from? Is generated first? Where name =? And date =? Use "?" in this way "?" As a placeholder statement, and then parse the parameters.

[2] use non-precompiled
<Select id = "hisNumber" parameterType = "hashmap" resultType = "hashmap" statementType = "STATEMENT"> select number from $ {oldTableName} <! -- Use "$" here "!!! --> Where name = '$ {name, jdbcType = VARCHAR}' and date = '$ {date, jdbcType = TIMESTAMP}' <select>

Note that the values of the following names and dates are in the '$ {name}' format. This will convert the Data Type of the parameters, which helps improve mysql query performance.

[3] non-precompiled
<Select id = "hisNumber" parameterType = "hashmap" resultType = "hashmap" statementType = "STATEMENT"> select number from $ {oldTableName} <! -- Use "$" here "!!! --> Where name =$ {name} and date =$ {date} <select>

Note that the values of name and date are in the $ {name} format. The parameter values are directly obtained without data type conversion. When the parameter is of the numeric type and the format is "00124", an error occurs in Data Reading (0124, 124, and so on ).

We recommend that you use the first method !!

Summary

The above is all about MyBatis parsing using dynamic tables or column code. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

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.