java使用mybatis根据id集合批量删除、修改数据

本文展示了如何使用MyBatis进行批量删除(实为逻辑删除)和更新操作。在Controller中通过Integer数组接收多个ID,Mapper接口使用@Param注解传入参数,Mapper XML文件中利用foreach标签遍历并构造SQL语句,更新指定记录的状态码和更新时间。
摘要由CSDN通过智能技术生成

1.在使用mybatis批量删除、修改数据时,mapper.xml代码和controller参数接收方式
controller

	@RequestMapping(value = "/deletePapersExpire", method = RequestMethod.GET)
    public ResultInfo<Boolean> deletePapersExpire(Integer[] keyIdList,String updateBy) {
        return new ResultInfo<>().succeed(taskPapersExpireService.deletePapersExpire(keyIdList,updateBy));
    }

mapper

Boolean deletePapersExpire(@Param("list") Integer[] keyIdList,String updateBy);

mapper.xml
因为我项目中所使用的是逻辑删除,所以使用update改变状态码

	<update id="deletePapersExpire">
        update task_papers_expire
        set
        task_statecode='DELETE',task_update_on=now(),task_update_by=#{updateBy,jdbcType=VARCHAR}
        where key_id in
        <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </update>
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值