本文小编为大家详细介绍“mybatis多个区间怎么处理”,内容详细,步骤清晰,细节处理妥当,希望这篇“mybatis多个区间怎么处理”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
如图:要实现车辆数不同区间查询条件
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 >= #{item2}
</if>
<if test="index2%2==1">
and sfi.count_cargo <= #{item2}
</if>
</foreach>
)
<!--最后一次不用加or-->
<if test="index != countCargoList.size-1" >
or
</if>
</foreach>
)
</if>
1、多个表的数据一起删除的时候,有的时候不会建立外键,但主表的关联 表很多的时候,可以直接利用mybatis 进行多表删除。
mybatis 中多个foreach 循环,第一次循环的collection 看到的值是一个(数组、list、map、对象,由collection的配置主导)。
第二次foreach 是直接copy第一个foreach的对象值,这个时候会一直累加对象。
数组为例
dao层去掉@Param注解
void batchDeleteSysTransferRegist(String rowData[]);
mybatis
<delete id="batchDeleteSysTransferRegist" parameterType="string">
delete from sys_transfer_regist_item where transfer_regist_id in
<foreach item="rowData" collection="array" open="(" separator="," close=")">
#{rowData}
</foreach>
;delete from sys_transfer_regist_piece where transfer_regist_id in
<foreach item="rowData1" collection="array" open="(" separator="," close=")">
#{rowData1}
</foreach>
......
</delete>
切记;隔开。
读到这里,这篇“mybatis多个区间怎么处理”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。