一、数组或集合的使用
1、在使用foreach的是collection属性,该属性是必须指定的,但是在不同情况下,该属性的值是不一样的,主要有一下4种情况:
-
- 如果传入的是单参数且参数类型是一个List的时候,collection属性值为list .
- 如果传入的是单参数且参数类型是非list的Collection的时候,collection属性值为collection .
- 如果传入的是单参数且参数类型是一个array数组的时候,collection的属性值为array
- 如果dao层指定了param的name,或者dao层传的是map,collection里为param的name或map的key
2、判断长度
集合:<if test="arr != null and arr.size() > 0">
数组:<if test="col != null and col .length > 0">
3、foreach使用
and plan_id in
<foreach collection="planIds" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
二、Like使用
travel_comment like CONCAT('%',#{cityName},'%')