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!