码迷,mamicode.com
首页 > 其他好文 > 详细

MyBatis参数传入集合之foreach用法

时间:2016-04-18 18:45:36      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

传入集合list

1   // 账户类型包括门店和分公司
2   List<Object> scopeList = new ArrayList<Object>();
3   scopeList.add(UserConstants.UserScope.STORE);
4   scopeList.add(UserConstants.UserScope.BRANCH_COMPANY);
5   params.put("scopeList", scopeList);
6   PageResult<UserDto> userPage = userService.getOtherAccountList(params);

mybatis的sql文件

 1 <select id="getOtherAccountList" resultMap="UserMap">
 2         SELECT <include refid="columns" />
 3         FROM sys_user 
 4         <where>
 5             <if test="scopeList !=null">
 6                 AND scope in <foreach collection="scopeList" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
 7             </if>
 8             <if test="account != null">
 9                 AND account LIKE CONCAT(‘%‘,#{account},‘%‘ )
10             </if>
11            <if test="shopId !=null">
12                 AND shop_id = #{shopId}
13             </if>
14             <if test="primary !=null">
15                 AND primary = #{primary}
16             </if>
17            <if test="status !=null">
18                 AND status = #{status}
19             </if>
20         </where>
21         order by id desc , create_time desc
22     </select>

collection是要遍历的参数集合,item是集合中每个项,取值就这样取#{item}

 

MyBatis参数传入集合之foreach用法

标签:

原文地址:http://www.cnblogs.com/chn58/p/5405228.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!