工作中Mybatis.xml 常用写法

工作中Mybatis.xml 常用写法
  • 大于、小于、等于的正确写法
符号原符号替换符号
小于<&lt;
小于等于<=&lt;= 或者 a <![CDATA[ <= ]]> b
大于>&gt;
大于等于>=&gt;= 或者 a <![CDATA[ >= ]]> b
&&amp;
单引号&apos;
双引号"&quot;
不等于!=a <![CDATA[ != ]]> b
  • List数据 条件查询(separator 属性为逗号)

最后渲染的结果为:and field in (‘xxx’,‘xxx’,‘xxx’)

<if test="paramList != null and paramList.size()>0">
      and field in
       <foreach collection="paramList" item="item" index="index"open="(" close=")" separator=",">
           #{item,jdbcType = VARCHAR}
       </foreach>
</if>
  • List数据条件查询(separator 属性为or)

最后渲染的结果为:where (post_name LIKE ‘%财务%’ OR post_name LIKE ‘%经理%’ OR post_name LIKE ‘%技术%’)

<if test="postNameList!=null and postNameList.size()>0">
       and
    <foreach collection="postNameList" open="(" close=")" separator=" or " item="item">
        post_name like  '%${item}%'
    </foreach>
</if>
  • 字段一般查询
<if test="param != null and param != ''">
    and field = #{param,jdbcType=VARCHAR}
</if>
  • 字段进行模糊查询
<if test="paramLike != null and paramLike != ''">
    and field like CONCAT(CONCAT('%',#{paramLike,jdbcType=VARCHAR}),'%')
</if>
  • BigDecimal范围查询
<if test="paramMax != null ">
      and field <![CDATA[ <= ]]> #{paramMax,jdbcType=DECIMAL}
</if>
<if test="paramMin != null ">
      and field <![CDATA[ >= ]]> #{paramMin,jdbcType=DECIMAL}
</if>
  • 判断参数等于具体值
<if test='param =="0"'>
     field = #{param,jdbcType=VARCHAR}
</if>
<if test="param =='0'.toString()">
    field = #{param}
</if>
<if test="paramList.size() == 1 and paramList.contains('0'.toString())">
     ......
</if>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小Java开发者

“是一种鼓励,你懂的”

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值