mybatis傳入字串,集合,陣列並遍歷
阿新 • • 發佈:2018-12-03
mybatis傳入字串,集合,陣列並遍歷
<!--傳遞引數為字串approveStatus =“通過,不通過” item為遍歷後的引數-->
<if test="approveStatus != null and approveStatus!=''">
and i.approve_status IN
<foreach item="status" collection="approveStatus.split(',')" open="(" separator="," close=")">
#{ status}
</foreach>
</if>
<!--傳遞引數為集合approveStatusList,集合中包含物件user ,approveStatusList={user1,user2 } -->
<if test="approveStatusList!= null and approveStatusList.size>0 ">
AND operate_user in
<foreach collection="approveStatusList" open="(" close=")" separator= "," item="user" index="index">
#{user.userName}
</foreach>
</if>
<!--傳遞引數為陣列approveStatus =[通過,不通過] 此時collection必須為array item為傳遞的陣列引數,且引數名要保持一致-->
<if test="approveStatus != null and approveStatus!=''">
and i.approve_status IN
<foreach item="approveStatus" collection="array" open="(" separator="," close=")">
#{approveStatus}
</foreach>
</if>