Mybatis Dynamic SQL

1. If <select id="findActiveBlogWithTitleLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <if test="title != null"> AND title like #{title} </if> </select> 2. Choose, When, Otherwise <select id="findActiveBlogLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <choose> # choose only one case among many options <when test="title != Read more

Mybatis foreach tag

Six Attributes collection: There are three formats: list, array, and map, according to the type of parameter passed. item: the parameter name of the set of objects in the tag. separator: the separator at the end of each sub-loop, usually “,”. open: start character, often “(“. close: end character, often Read more

MySQL Strings Segmentation

SUBSTRING_INDEX(str, delim, count) str: the string to be split. delim: the delimiter. count: the position of the delimiter. A positive number means extract from left to right, a negative number means extract from right to left. For example: SELECT SUBSTRING_INDEX('100-200-300-400', '-', 1); — output: '100' SELECT SUBSTRING_INDEX('100-200-300-400', '-', 2); — Read more