MyBatis Plus自定义更新

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

/**
 * 是想对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);
相关文章
相关标签/搜索