以下面代码为例
<if test="query.standValueIds != null and query.standValueIds.size > 0">
and
table.id in (
select a.product_id from (
<foreach collection="query.standValueIds" item="item" separator="union all" open="(" close=")">
select distinct pp.product_id
from product_parameter as pp
where pp.stand_value_id = #{item}
</foreach>
) as a
// 获取集合长度时,不能在利用常规的#{query.standValueIds.size}获取,必须使用${query.standValueIds.size}一下方法
GROUP BY a.product_id HAVING COUNT(*) = ${query.standValueIds.size})
</if>
GROUP BY a.product_id HAVING COUNT(*) = ${query.standValueIds.size},就在此处不能使用#{}获取,而是用${}方式.