MyBatis中模糊查询的使用

使用<bind/>标签进行模糊查询

bind 元素可以从 OGNL 表达式中创建一个变量并将其绑定到上下文,bind适用于mysql,sql server,oracle

 <select id="getGoodsCondition" parameterType="Goods" resultType="Goods">
        select * from mall_goods
        <where>
            <if test="name!=null and name!=''">
                <!--name,为目标数据源取名-->
                 <!--value,值的表达式-->
                <bind name="goodsName" value="'%' + name + '%'"/>
                name like #{goodsName}
            </if>
          </where>
    </select>            

  #{ }中的名字与,bind标签中的 name一致!

posted @ 2020-06-16 21:42  木子李和三点水  阅读(497)  评论(0编辑  收藏  举报