1、增删查改
简单操作plus,
// 查询
QueryWrapper<Bo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("trader_no",bo.getTraderNo());
//条件更新
UpdateWrapper<Bo> wrapper = new UpdateWrapper<>();
wrapper.eq("trader_no",bo.getTraderNo());
wrapper.set(StringUtils.isNotEmpty(bo.getContact()),"contact",bo.getContact());
wrapper.set("update_user",bo.getUpdateUser());
extraMapper.update(null, wrapper);
//如果使用实例更新,需要注意,默认不更新为空的值
extraMapper.upadte(b0)
mybatis-plus 更新有三种策略:
IGNORED:0 忽略
NOT_NULL:1 非 NULL,默认策略
NOT_EMPTY:2 非空
通过接口更新数据时数据为NULL值时将不更新进数据库。
解决方式如:更新时无法置空的解决
2、使用lamada表达式
LambdaUpdateWrapper<Article> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(Article::getOfflineTime,null);
updateWrapper.eq(Article::getId,article.getId());
int i = articleMapper.update(article, updateWrapper);