批量更新数据 dao层传多个参数

1.dao层接口

    void updateOperationCheck(@Param("startTime")Date startTime, @Param("endTime")Date endTime,@Param("list")List<MotOperationCheck> list );

 2.mybatis中对应方法

 <update id="updateOperationCheck">
        UPDATE YTMOT.T_MOT_OPERATION_CHECK
        SET
        CALCULATION_S_TIME= to_char(#{startTime},'yyyy-MM-dd HH:mm:ss'),
        CALCULATION_E_TIME= to_char(#{endTime},'yyyy-MM-dd HH:mm:ss')
        <where>
            ID IN
            <foreach collection="list" item="bean" index="" open="(" close=")" separator=",">
                #{bean.id}
            </foreach>
        </where>
    </update>

运行ok

注意:

   foreach标签中collection代表传入得参数名,item可以自己取名,但是访问List中得数据就必须使用自定义名.去访问 ,因为用到了IN,所以就用open,close,括号,用separator逗号分隔。

猜你喜欢

转载自blog.csdn.net/xiaojinsanMM/article/details/84026351