foreach传入List为空
<select id="listAccounts" resultMap=" ">
select *
from tbl_**
where is_deleted = 0
<if test="accountReq.onlineStatus == 1 and onlineClients != null and onlineClients.size()>0">
AND id IN
<foreach collection="onlineClients" item="onlineClient" index="index" open="(" close=")" separator=",">
#{onlineClient}
</foreach>
</if>
<if test="accountReq.onlineStatus == 2 and onlineClients != null and onlineClients.size()>0">
AND id NOT IN
<foreach collection="onlineClients" item="onlineClient" index="index" open="(" close=")" separator=",">
#{onlineClient}
</foreach>
</if>
<if test="accountReq.username != null and accountReq.username != ''">
and username = #{accountReq.username,jdbcType=VARCHAR, typeHandler=com.cmiov.base.dcommon.mybatis.AESEncryptHandler}
</if>
</select>
1.将在线消息客户端id保存在List中传入SQL;
2.判断前端传入的筛选条件(onlineStatus),分别讨论查询出结果;
3.需要重点考虑传入的List是否为空,非null的条件下,还要保证List的size大于0,否则不能走foreach语句,会报空指针异常。