The My Batis official documentation shows less of the scenarios and effects of using trim tags in dynamic SQL.
In fact the 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
Like what:
Java code
- Select b.* from Sys_menu b where 1 = 1
- <trim suffix="WHERE" suffixoverrides="and | OR ">
- <if test="id! = NULL and ID! =" ">
- and b.ID =#{id}
- </if>
- <if test="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
- <trim suffix="WHERE" suffixoverrides="and | OR ">
Suffix is the append suffix suffix value for suffixoverrides compliant SQL statements.
Word:
Java code
- <trim suffix="WHERE" suffixoverrides="and | OR ">
and sqlxxx
The end result is:
and Sqlxxx WHERE
I'm not quite sure of the specifics of this usage, but many of the tags are sufficient for the current MyBatis dynamic SQL statement.
MyBatis use of Trim tags in dynamic sql