sql里面for循环(sql语句中foreach循环)

sql里面for循环(sql语句中foreach循环)pre List lt Integer gt pre Long 1 findByIds List lt Integer gt ids 传入参数为单一 list 参数时的写法 lt foreach item id index index

大家好,我是讯享网,很高兴认识大家。



 <pre>List&lt;Integer&gt;</pre> 

讯享网


讯享网


讯享网Long[] 

1. findByIds(List&lt;Integer&gt; ids) 传入参数为单一list参数时的写法
 &lt;foreach item=“id” index=“index” collection=“list”  open=“(” separator=“,” close=“)”&gt;  
         #{id}                
 &lt;/foreach&gt;
2. findByIds(Integer[] ids) 传入参数为单一数组时的写法
 
 &lt;foreach item=“id” index=“index” collection=“array”  open=“(” separator=“,” close=“)”&gt;  
         #{id}               
 &lt;/foreach&gt;
 
3. search(Integer[] ids,String title) 传入参数为多个类型的查询条件时 
Map&lt;String, Object&gt; params = new HashMap&lt;String, Object&gt;();
params.put(“title”, title);
params.put(“ids”, ids);
 &lt;foreach item=“id” index=“index” collection=“ids”  open=“(” separator=“,” close=“)”&gt;  
         #{id}               
 &lt;/foreach&gt;
 
4.search(Person person) 传入参数为bean对象
 &lt;foreach item=“id” index=“index” collection=“person.ids”  open=“(” separator=“,” close=“)”&gt;  
         #{id}               
 &lt;/foreach&gt;
 
四种方式应用不同的场景,主要是collection的参数不同

————————————————

                            版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.csdn.net/gavin5033/article/details/

小讯
上一篇 2025-05-09 22:05
下一篇 2025-05-01 14:54

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/207121.html