<select id="selectTrafficEventIngByType" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from T_TRAFFIC_EVENT
where to_char(EVENT_TIME,'dd')=to_char(sysdate,'dd')
and ROWNUM <![CDATA[ <= ]]> 100
<if test="eventType!=null and eventType!='' ">
and EVENT_TYPE in
<foreach collection="eventType" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="eventLevel!=null and eventLevel!='' ">
and EVENT_LEVEL in
<foreach collection="eventLevel" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
order by EVENT_TIME desc
</select>
从上面可以看到,where条件后需要对两个集合进行遍历,解决办法就是把这两个集合放入map中,foreach中的collection分别对应参数map中的key即可。
如下controller层代码:
Map map = new HashMap<>();
map.put("eventLevel", listLevel);
map.put("eventType", listType);
List<TrafficEventModel> events = trafficeEventServer.selectTrafficEventIngByType(map);
其中service和dao层参数类型写成Map<String,Object>即可。