1. 程式人生 > >mybatis中對List使用in語法,foreach語法

mybatis中對List使用in語法,foreach語法

service中程式碼

    public Integer deleteAlarmCountResultLogical(String deleted, ArrayList<String> idList){
        HashMap<String, Object> map = new HashMap<>(4);

        map.put(”ids“,idList);
        map.put(”status“,deleted);
        return mapper.deleteAlarmCountResultLogical(map);
    }

mapper中介面程式碼

Integer deleteAlarmCountResultLogical(Map<String, Object> map);

xml檔案中寫法:
<update id="deleteAlarmCountResultLogical" parameterType="java.util.Map">
    update alarm_count_result set

    <if test="status != null and status != '' ">
        status = #{status}
    </if>
    where id in
    <!--這裡的id對應map中的key-->
    <foreach close=")" collection="id" item="listItem" open="(" separator=",">
        #{listItem}
    </foreach>
</update>