mybaits中传入数组参数

来源:互联网 发布:eminem与光明会 知乎 编辑:程序博客网 时间:2024/05/18 02:10

下面介绍两种mybatis中传入数组参数的方法

第一种:直接传递数组数据

mapper中的配置:


[html] view plain copy
 print?
  1. <delete id="deleteBrandByIdsArray" parameterType="Integer[]">  
  2.     delete from bbs_brand  
  3.     <where>  
  4.         id  
  5.         <foreach  collection="array" item="id" open="in (" close=")" separator=",">   
  6.             #{id}  
  7.         </foreach>  
  8.     </where>  
  9. </delete>  
[html] view plain copy
 print?
  1. service中的配置:  
[html] view plain copy
 print?
  1. public void deleteBrandById(Integer[] ids) {  
  2.         brandMapper.deleteBrandByIdsArray(ids);  
  3.     }  

第二种:将数组放在map中传递:

mapper中的配置:

[html] view plain copy
 print?
  1. <delete id="deleteBrandByIds" parameterType="java.util.Map">  
  2.         delete from bbs_brand  
  3.         <where>  
  4.             id  
  5.             <foreach  collection="ids" item="id" open="in (" close=")" separator=",">   
  6.                 #{id}  
  7.             </foreach>  
  8.         </where>  
  9.     </delete>  

阅读全文
0 0
原创粉丝点击