Mybatis中的like模糊查询功能
程序员文章站
2024-03-06 12:19:43
1. 参数中直接加入%%
param.setusername("%cd%");
param.setpassword("%11%");
&...
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
where username like concat(concat('%',#{username}),'%')
以上所述是小编给大家介绍的mybatis中的like模糊查询功能,希望对大家有所帮助