关于 Mapper 和 ServiceImpl 中执行数据功能的问题 ?

作者站长头像
站长
· 阅读数 10

概述

文件结构

关于 Mapper 和 ServiceImpl  中执行数据功能的问题 ?

问题描述

XXXServiceImpl.java 中 我想要执行修改操作 出现了两组方法, a. 一组来组于 Mapper , baseMapper.update b. 一组来组于 ServiceImpl,this.update关于 Mapper 和 ServiceImpl  中执行数据功能的问题 ?

问题集合

  1. 我在serviceimpl 这个层面 应该怎么用。 1.1【不使用this.update, 只用 mapper 中的】 1.2【当前实体 使用this.update, 其他实体使用相应mapper】 1.3【其他】
回复
1个回答
avatar
test
2024-07-14

使用Mapper的update即可。


至于ServiceImpl中的update。可以点进去看看

IService.class
/**
 * 根据 whereEntity 条件,更新记录
 *
 * @param entity        实体对象
 * @param updateWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper}
 */
default boolean update(T entity, Wrapper<T> updateWrapper) {
    return SqlHelper.retBool(getBaseMapper().update(entity, updateWrapper));
}
回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容