<if test="recordTypes!=null">
and d.record_type in
<foreach collection="recordTypes" item="recordType" index="index" open="(" close=")" separator="," >
#{recordType,jdbcType=VARCHAR}
</foreach>
</if>
recordTypes是一个集合,之前因为 collection的值写了"#{recordTypes}",所以就读到了null,上面是正确写法。
mybatis还可以直接遍历类似 “1,21,3,5,99” 这样的字符串,利用split方法将字符串遍历成数组
<if test="entity.id!=null and entity.id!=''">
and t.id in
<foreach collection="entity.id.split(',')" item="id" index="index" open="(" close=")" separator="," >
#{id,jdbcType=NUMERIC}
</foreach>
</if>