mybatis xml檔案中的大於、小於、及like模糊查詢的寫法
阿新 • • 發佈:2018-11-07
在xml中,特殊符號的轉義寫法如下:
< <
> >
<> <>
& &
' '
" "
也可以使用<![CDATA[ ]]>
符號進行說明,將此類符號不進行解析
<![CDATA[ sql語句 ]]>
- 1
mysql like的寫法:
1.傳入引數中直接加入%%
param.setUsername("%CD%");
param.setPassword("%11%");
<select id="selectPersons" resultType="person" parameterType="person"> select id,sex,age,username,password from person where true <if test="username!=null"> AND username LIKE #{username}</if> <if test="password!=null">AND password LIKE #{password}</if> </select>
2.bind標籤
<select id="selectPersons" resultType="person" parameterType="person">
<bind name="pattern" value="'%' + _parameter.username + '%'" />
select id,sex,age,username,password from person
where username LIKE #{pattern}
</select>
3.CONCAT
like concat('%',#{param},'%')