dao层 ITemplateDao.java:
List<BrokerTemplate> GetTemplateListByIds(@Param(value = "ids") List<Long> ids);
resource:Template.xml
<select id="GetTemplateListByIds" resultMap="BrokerTemplate">
SELECT tb1.broker_template_id,
tb1.broker_id,
tb1.type,
tb1.content,
tb1.is_default,
tb1.create_time,
tb1.update_time,
tb1.is_deleted,
tb1.delete_time,
tb1.name,
tb1.`is_locked`
FROM broker_template tb1
WHERE broker_template_id IN
<foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
<foreach>中 属性如下
collection :是遍历的数据集合,这里是我的list<Long> ids。
item : 每个子项命名。需要跟foreach内使用时一致,这里是#{id}
index:索引位置
open :在遍历执行之前先附加的字符串。
close : 在遍历执行完成后附加的字符串。
separator:遍历每个item子项后附加的字符串(即子项之间自定义的间隔符号)
栗子: open="(" close=")" separator="," 拼出来就是 ( item1,item2, item3 )