mybatis in循环删除属性多条件参数

该文章展示了如何使用MyBatis进行批量删除操作,通过Map传递参数,利用foreach遍历List集合来构建IN语句。同时,文中还包含了一个条件查询的示例,涉及到IF标签和LIKE操作符的使用,用于根据输入条件过滤数据。
摘要由CSDN通过智能技术生成
<delete id="deletetest">
    DELETE FROM user where id in
    <foreach item="ids" collection="list" open="(" separator="," close=")">
        #{ids}
    </foreach>
    and age = #{age}
</delete>

collection="list"  对应map中key值

item="ids"    ids可以随意起名   注意跟#{ids} 保持一致即可

List<String> list = new ArrayList<>();
list.add("21");
list.add("22");
TestVO testVO = new TestVO();
testVO.setAge(22);
testVO.setIds(list);
Map<String, Object> map = new HashMap<>();
map.put("list",list); //数据库字段1
map.put("age",22);    //数据库字段2
userMapper.deletetest(map);
return Result.success(true);

<foreach collection="map.staffIdList" item="visit_id"
         open="("  separator="," close=")">
    ${visit_id}   // #{}   可能会 报下表越界异常  原因未知
</foreach>



<if test="map.staffIdList != null and map.staffIdList.size > 0 ">
    AND a.visit_id IN
    <foreach collection="map.staffIdList" item="visit_id"
             open="("  separator="," close=")">
        ${visit_id}
    </foreach>
</if>
<if test="map.customerSearch != null and map.customerSearch != ''">
    AND (b.staff_name LIKE '%${map.customerSearch}%'
    OR a.member_id LIKE '%${map.customerSearch}%'
    OR a.member_name LIKE '%${map.customerSearch}%')
</if>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值