Mybatis模糊查詢(like)
阿新 • • 發佈:2017-11-07
val ons param pass bin size user att pat
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拼接sql
where username LIKE concat(concat(‘%‘,#{username}),‘%‘)
Mybatis模糊查詢(like)