Mybatis 中遍曆map 參數中的 list 和 array 屬性__mybatis

來源:互聯網
上載者:User
問題

在項目有中遇到大量刪除操作時,需要根據兩個屬性去刪除資料,其中一個是類型: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層
@Overridepublic 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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.