首页 > 其他 > 详细

foreach

时间:2018-12-31 18:22:04      阅读:203      评论:0      收藏:0      [点我收藏+]

使用List:
<!-- ids为List<Integer> -->
<if test="ids!=null and ids.size()>0">
<!-- 方法1:foreach达到的效果: (t.id=1 or t.id=2 or t.id=3)
and <foreach collection="ids" index="index" item="item" open="(" separator="or" close=")">
t.id=#{item}
</foreach> -->

<!-- 方法2:foreach达到的效果:(1,2,3) -->
and t.id in <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>


使用int[]:
<!-- ids为int[] -->
<if test="ids!=null and ids.length>0">
<!-- 方法1:foreach达到的效果:(t.id=1 or t.id=2 or t.id=3)
and <foreach collection="ids" index="index" item="item" open="(" separator="or" close=")">
t.id=#{item}
</foreach> -->

<!-- 方法2:foreach达到的效果:(1,2,3) -->
and t.id in <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>

foreach

原文:https://www.cnblogs.com/thaipine/p/10202578.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!