MyBatis Plus自定义更新

之前接触的MyBatis Plus的更新都是updateById的形式,但是想根据其它条件更新呢,百度了都没有具体说怎么做,下面亲测方法:

/**
 * 是想对BusMail(bus_mail表)进行以下更新:
 * update bus_mail set mailStatus = 3 where reciver = #{userId} and mailStatus = 1
 */
BusMail e = new BusMail();
e.setMailStatus(3);
EntityWrapper<BusMail> ew = new EntityWrapper<BusMail>();
        
// 错误更新方式
ew.where("reciver", userId);
ew.and("mailStatus", 1);
baseMapper.update(e, ew);
        
// 第一种更新方式
ew.where("reciver = {0}", userId);
ew.and("mailStatus = {0}", 1);
baseMapper.update(e, ew);
        
// 第二种更新方式
ew = new EntityWrapper<BusMail>();
ew.where("reciver = {0} and mailStatus = {1}", new Object[]{userId, 1});
baseMapper.update(e, ew);
        
// 第三种更新方式
ew = new EntityWrapper<BusMail>();
ew.eq("reciver", userId);
ew.eq("mailStatus", 1);
baseMapper.update(e, ew);

 

转载于:https://my.oschina.net/u/1790105/blog/1583529

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值