mybatis多个区间处理(双foreach循环)

本文介绍了一种在MyBatis中实现车辆数不同区间查询的方法。通过前端传递包含区间字符串的数组,后端利用MyBatis的双foreach循环解析,实现对数据的精确筛选。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 
如图:要实现车辆数不同区间查询条件
 
 
 
 
思路:a.前端传数组,数组里面放"1-5"String类型值
 
          b.后端mybatis用双foreach循环解析
 
 
后端代码如下:
  <!--图例车辆数区间-->
      <if test="countCargoList != null and countCargoList.size>0" >
          and (
          <foreach item="item" index="index" collection="countCargoList">
              (
            <foreach item="item2" index="index2" collection="item.split('-')">

                <if test="index2%2==0">
                    sfi.count_cargo &gt;= #{item2}
                </if>

                <if test="index2%2==1">
                    and sfi.count_cargo &lt;= #{item2}
                </if>

            </foreach>
              )
              <!--最后一次不用加or-->
              <if test="index != countCargoList.size-1" >
                  or
              </if>
          </foreach>
          )
      </if>

 

 
 

转载于:https://www.cnblogs.com/ejQiu-123/p/11448175.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值