zoukankan      html  css  js  c++  java
  • Mybatis 中遍历map 参数中的 list 和 array 属性

    原文:https://blog.csdn.net/liudongdong0909/article/details/51048835

    问题
    在项目有中遇到批量删除操作时,需要根据两个属性去删除数据,其中一个是类型: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>
  • 相关阅读:
    shiro实战系列(三)之架构
    shiro实战系列(二)之入门实战续
    ShopNC B2B2C多用户商城2014商业版,带微商城
    开源 SHOPNC B2B2C结算营运版 wap IM客服 API 手机app 短信通知
    PHP5.3下加速器ZendGuardLoader安装 (LNMP/lnmpa)
    XAMPP + Xdebug+Zend Studio
    magento 12 配置安装教程
    C#控件一览表
    GetXamarin.xambe
    新建电子监控点与测速点
  • 原文地址:https://www.cnblogs.com/shihaiming/p/10370409.html
Copyright © 2011-2022 走看看