Mybatis的模糊查询
方法1:在其它地方對(duì)其進(jìn)行相關(guān)處理,語(yǔ)句與正常的查詢(xún)無(wú)異
在sqlMap中與正常的無(wú)異,如下所示:
<select id="getNovaUserInfoByNickLike" resultMap="novaUserInfoMap">
??<include refid="selectNovaUserInfoAll"/>??
?? where
??nick like #{nick} order by createdAt desc?
?</select>
?
public List<NovaUserInfo> getNovaUserInfoByNickLike(@Param(value = "nick")String nick);
在Dao的接口中與正常查詢(xún)無(wú)異:
public List<NovaUserInfo> getNovaUserInfoByNickLike(String nick);
在Dao的實(shí)現(xiàn)中要做一些簡(jiǎn)單的操作:
@Override
public List<NovaUserInfo> getNovaUserInfoByNickLike(String nick,PageQuery pageQuery) {
??return this.novaUserInfoMapper.getNovaUserInfoByNickLike("%"+nick+"%");
?}
?
ibatis中配置模糊查詢(xún):
<select id="getNovaUserInfoByNickLike" resultMap="novaUserInfoMap">
??<include refid="selectNovaUserInfoAll"/>??
?? where
??nick like '%$sname$%' order by createdAt desc?
?</select>
?
select sname,sid from student where sname like '%$sname$%';
?
方法2:直接在sql語(yǔ)句中寫(xiě),其它的不變
第一種方法
<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>
?
第二種方法
<select id="getNovaUserInfoByNickLike" resultMap="novaUserInfoMap">
??<include refid="selectNovaUserInfoAll"/>??
?? where
??nick like CONCAT('%','?#{nick}','%'?) order by createdAt desc?
?</select>
總結(jié)
以上是生活随笔為你收集整理的Mybatis的模糊查询的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: coreseek mysql_cores
- 下一篇: 6用NetBeans进行JSP开发