Mybatis 中遍历map 参数中的 list 和 array 属性

问题

在项目有中遇到批量删除操作时,需要根据两个属性去删除数据,其中一个是类型:type, 另一个是ids:数组形式的id数组。由于在官方文档中只是简单的介绍foreach的用法,套用之后进行批量删除操作:提示遍历map中的array 属性是无法获取值。

解决方案

通过重新阅读mybatis 3 官方文档, 查阅CSDN iteye等网站资料。

代码

controller层

/**
 *[根据附件的类型 type 和 对象ids批量删除附件信息]
 */
@RequestMapping("/deleteProjectInterimByIds.do")
public void deleteProjectInterimByIds(HttpServletResponse response, 
@RequestParam(value = "ids", required=true)Long[] ids,
@RequestParam(value="type",required=true)Integer type) {
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("type", type);
        paraMap.put("ids", ids);
        int i =  nterimAttService.deleteAttachmentByObjIdsAndType(paraMap);
        System.out.println(i);

dao层

@Override
public int deleteAttachmentByObjIdsAndType(Map<String, Object> paraMap) {
    return this.getSqlSession().delete(NAME_SPACE +"batchDeleteAttByIds", paraMap);
    }

mapper.xml

<–1.取map中的key 为type的值
2.取map中的key 为ids 的值;Ids 在map中是以数组的形式存在 的,直接标记取出就可以,采用#{des}的方式会出现错误;–>


<delete id="batchDeleteAttByIds" parameterType="map">
    delete from project_attachments
    where attachment_type = #{type} and object_id in 
    <foreach collection="ids" open="(" close=")" separator="," item="id">
        #{id}
    </foreach> 
  </delete>
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值