注意这里如果使用#会报错,所以使用$符号,如果不是数字类型,比如long,integer,还需加上单引号''。代码片段如下:
<if test="pd.publishIds != null and pd.publishIds!= ''">
and p.publishId in
<foreach collection="pd.publishIds" item="pId" index="index"
open="(" close=")" separator=",">
'${pId}'
</foreach>
</if>
pId是类似于"a,b,c,d,e,f"的字符串,用逗号隔开。