mybatis模糊查询实现

来源:互联网 发布:php 跨平台 编辑:程序博客网 时间:2024/05/22 01:56
最近在用mybatis做模糊查询的时候,这个‘%xx%’不知道怎么插入,直接写在sql语句里面没法实现,在网上查了一下主要有两种比较好的方式实现


1.使用<bind>标签
<select>
    <bind name="pattern" value="'%'+_parameter+'%'">
    select * from table where field like #{pattern}
</select>
注意:_paramter代指传入的参数,如果参数类型是基本数据类型或者它们对于的类类型,就直接写_paramter,如果是包装类型,写为_paramter.getter()       getter()代指对应字段的get方法


2.使用concat
sql语句写为 select * from table where field like concat('%','${field}','%')
               或 select * from table where field likeconcat('%',#{field},'%')



0 0
原创粉丝点击