在 mapper 层或 dao 层中,参数是一个 list,所以在 XML 中的 SQL,需要 foreach 放在 in 的条件中进查询。其中 collection 是mapper层或dao的参数,item是list中的对象,index是item对象在list中的索引,open则是 list 以“(”左括号开始,item之间用逗号“,”隔开,以“)”为list结束的标志。
2 代码select category4_id, category4_name, t1.category3_id, t1.category3_name from tb_categoryview t1 join( select distinct category3_id from tb_select_devicesview where category2_id in3 foreach 标签#{item} ) t2 on t1.category3_id = t2.category3_id and materialgroup4_name is not null and t1.materialgroup3_name is not null order by category4_id
关键的SQL是:主要是对 foreach 的使用
4 如果 list 的 size 比较小的情况下,或确定的情况#{item}
select category4_id, category4_name, t1.category3_id, t1.category3_name
from tb_categoryview t1 join(
select distinct category3_id from tb_select_devicesview
where category2_id in ('A01', 'C02', 'B01')
) t2
on t1.category3_id = t2.category3_id
and materialgroup4_name is not null
and t1.materialgroup3_name is not null
order by category4_id
即 list 是确定的,可一一列举的情况。



