One, My batis trim tag is somewhat similar to the replace effect.
Trim property,
Prefix: Prefixes overwrite and increase their contents
Suffix: suffixes overwrite and increase their contents
Prefixoverrides: Criteria for judging prefixes
Suffixoverrides: The condition of the suffix judgment
For example: Java SQL statements are as follows,
Select b.* from Sys_menu b where 1 = 1<Trimsuffix= "WHERE"Suffixoverrides= "and | OR "> <ifTest= "id! = NULL and ID! =" ">and b.id =#{id}</if> <ifTest= "name = NULL">and b.menu_name like #{name}</if> </Trim>
The final SQL print is:
Select b.* from Sys_menu b where 1 = 1 and b.menu_name "where"
From the results can be found:
Java code:
<suffix= "WHERE" suffixoverrides= "and | OR ">
Suffix is the append suffix suffix value for suffixoverrides compliant SQL statements.
Second, the award equals the time of experience "turn"
In the use of mybatis operation of the database when I believe that many people use, when in the judgment null, greater than, greater than, less than, less than equals, not equal to the estimated a lot of use, easier to achieve, here is omitted, but only the judgment condition is equal when estimated quite a lot of people encounter pits, I have been on this issue for almost a day, so the experiment summarized and briefly recorded;
When the mybatis determines that the condition is equal, the constant needs to be added. ToString () to convert, This method is stable and recommended , such as:
<!-- correct, stable, recommended; CDATA labels to prevent errors in parsing < and > symbols -
<test= "Newsimage! = null and Newsimage = = ' 1 '. toString ()"> 3 <! [cdata[]]> </if >
newsimage = = ' 1 '. toString () .tostring () do the casting operation, MyBatis know is the value of the comparison of content, of course, succeeded; Note that this constant is not limited to numbers, and for letters, such as ' Y ', you also need to add .tostring ()
<!--- <test = "Newsimage! = null and Newsimage = = ' y '. toString () "> <![ cdata[]]> </if>
Three, fuzzy query and character splicing
<SelectID= "GetData"ParameterType= "Map"Resulttype= "Map">Select from Swweb. FK<where><ifTest= "Starttime!=null and starttime!="> <! [Cdata[and Zbtime>=to_date (#{starttime}, ' Yyyy-mm-dd ')]]></if>
<ifTest= "Finishtime!=null and finishtime!="> <! [Cdata[and Zbtime<=to_date (#{finishtime}, ' Yyyy-mm-dd ')]]></if>
<!--character stitching Blur query --<ifTest= "Keywords!=null and keywords!="> <! [Cdata[and (CONTENT like CONCAT (CONCAT ('% ', #{keywords}), '% '))]]></if><ifTest= "Zbd_name!=null and zbd_name!="> <! [Cdata[and (ZBD like CONCAT (CONCAT ('% ', #{zbd_name}), '% '))]]></if></where>ORDER BY zbtime Desc</Select>
Mybatis:trim tag, "equals = =" experience, CDATA label, Fuzzy query concat,like