java.lang.Object
com.baomidou.mybatisplus.extension.toolkit.Db

public class Db extends Object
以静态方式调用Service中的函数
从以下版本开始:
2022-05-03
作者:
VampireAchao
  • 方法概要

    修饰符和类型
    方法
    说明
    static <T> long
    count(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    根据 Wrapper 条件,查询总记录数
    static <T> long
    count(Class<T> entityClass)
    查询总记录数
    static <T> long
    count(T entity)
    根据entity中不为空的数据查询记录数
    static <T> T
    getById(Serializable id, Class<T> entityClass)
    根据 ID 查询
    protected static <T> Class<T>
    getEntityClass(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    从wrapper中尝试获取实体类型
    protected static <T> Class<T>
    getEntityClass(Collection<T> entityList)
    从集合中获取实体类型
    protected static <T> Class<T>
    getEntityClass(T entity)
    从entity中尝试获取实体类型
    static <T> Map<String,Object>
    getMap(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    根据 Wrapper,查询一条记录
    static <T> Map<String,Object>
    getMap(T entity)
    根据 entity不为空条件,查询一条记录
    static <T, V> V
    getObj(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper, com.baomidou.mybatisplus.core.toolkit.support.SFunction<? super T,V> mapper)
    根据 Wrapper,查询一条记录
    static <T> T
    getOne(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    根据 Wrapper,查询一条记录
    static <T> T
    getOne(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper, boolean throwEx)
    根据 Wrapper,查询一条记录
    static <T> T
    getOne(T entity)
    根据 entity里不为空的字段,查询一条记录
    static <T> T
    getOne(T entity, boolean throwEx)
    根据 entity里不为空的字段,查询一条记录
    protected static <T> com.baomidou.mybatisplus.core.metadata.TableInfo
    getTableInfo(Class<T> entityClass)
    获取表信息,获取不到报错提示
    static <T> com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper<T>
    ktQuery(Class<T> entityClass)
    kt链式查询
    static <T> com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper<T>
    ktUpdate(Class<T> entityClass)
    kt链式更改
    lambdaQuery(Class<T> entityClass)
    链式查询 lambda 式
    lambdaUpdate(Class<T> entityClass)
    链式更改 lambda 式
    static <T> List<T>
    list(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    查询列表
    static <T> List<T>
    list(com.baomidou.mybatisplus.core.metadata.IPage<T> page, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
     
    static <T> List<T>
    list(com.baomidou.mybatisplus.core.metadata.IPage<T> page, Class<T> entityClass)
     
    static <T> List<T>
    list(com.baomidou.mybatisplus.core.metadata.IPage<T> page, T entity)
    根据entity中不为空的字段进行查询
    static <T> List<T>
    list(Class<T> entityClass)
    查询所有
    static <T> List<T>
    list(T entity)
    根据entity中不为空的字段进行查询
    static <T> List<T>
    listByIds(Collection<? extends Serializable> idList, Class<T> entityClass)
    查询(根据ID 批量查询)
    static <T> List<T>
    listByMap(Map<String,Object> columnMap, Class<T> entityClass)
    查询(根据 columnMap 条件)
    static <T> List<Map<String,Object>>
    listMaps(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    查询列表
    static <T> List<Map<String,Object>>
    listMaps(com.baomidou.mybatisplus.core.metadata.IPage<? extends Map<String,Object>> page, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
     
    static <T> List<Map<String,Object>>
    listMaps(com.baomidou.mybatisplus.core.metadata.IPage<? extends Map<String,Object>> page, Class<T> entityClass)
    分页查询列表
    static <T> List<Map<String,Object>>
    listMaps(com.baomidou.mybatisplus.core.metadata.IPage<? extends Map<String,Object>> page, T entity)
    根据entity不为空的条件查询列表
    static <T> List<Map<String,Object>>
    listMaps(Class<T> entityClass)
    查询所有列表
    static <T> List<Map<String,Object>>
    listMaps(T entity)
    根据entity不为空的条件查询列表
    static <E, T> List<E>
    listObjs(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    根据 Wrapper 条件,查询全部记录
    static <T, V> List<V>
    listObjs(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper, com.baomidou.mybatisplus.core.toolkit.support.SFunction<? super T,V> mapper)
    根据 Wrapper 条件,查询全部记录
    static <T> List<T>
    listObjs(Class<T> entityClass)
    查询全部记录
    static <T, V> List<V>
    listObjs(Class<T> entityClass, com.baomidou.mybatisplus.core.toolkit.support.SFunction<? super T,V> mapper)
    查询全部记录
    static <T> com.baomidou.mybatisplus.core.metadata.IPage<T>
    page(com.baomidou.mybatisplus.core.metadata.IPage<T> page, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    翻页查询
    static <T> com.baomidou.mybatisplus.core.metadata.IPage<T>
    page(com.baomidou.mybatisplus.core.metadata.IPage<T> page, Class<T> entityClass)
    无条件翻页查询
    static <T, E extends com.baomidou.mybatisplus.core.metadata.IPage<Map<String, Object>>>
    E
    pageMaps(E page, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    翻页查询
    static <T, E extends com.baomidou.mybatisplus.core.metadata.IPage<Map<String, Object>>>
    E
    pageMaps(E page, Class<T> entityClass)
    无条件翻页查询
    static <T> QueryChainWrapper<T>
    query(Class<T> entityClass)
    链式查询 普通
    static <T> boolean
    remove(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
    根据 entity 条件,删除记录
    static <T> boolean
    removeById(Serializable id, Class<T> entityClass)
    根据 ID 删除
    static <T> boolean
    removeById(T entity)
    根据实体(ID)删除
    static <T> boolean
    removeByIds(Collection<? extends Serializable> list, Class<T> entityClass)
    删除(根据ID 批量删除)
    static <T> boolean
    removeByMap(Map<String,Object> columnMap, Class<T> entityClass)
    根据 columnMap 条件,删除记录
    static <T> boolean
    save(T entity)
    插入一条记录(选择字段,策略插入)
    static <T> boolean
    saveBatch(Collection<T> entityList)
    插入(批量)
    static <T> boolean
    saveBatch(Collection<T> entityList, int batchSize)
    插入(批量)
    static <T> boolean
    saveOrUpdate(T entity)
    TableId 注解存在更新记录,否插入一条记录
    static <T> boolean
    saveOrUpdate(T entity, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> updateWrapper)
    根据updateWrapper尝试更新,否继续执行saveOrUpdate(T)方法 此次修改主要是减少了此项业务代码的代码量(存在性验证之后的saveOrUpdate操作)
    static <T> boolean
    批量修改插入
    static <T> boolean
    saveOrUpdateBatch(Collection<T> entityList, int batchSize)
    批量修改插入
    static <T> boolean
    update(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> updateWrapper)
    根据 UpdateWrapper 条件,更新记录 需要设置sqlset
    static <T> UpdateChainWrapper<T>
    update(Class<T> entityClass)
    链式更改 普通
    static <T> boolean
    update(T entity, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> updateWrapper)
    根据 whereEntity 条件,更新记录
    static <T> boolean
    updateBatchById(Collection<T> entityList)
    根据ID 批量更新
    static <T> boolean
    updateBatchById(Collection<T> entityList, int batchSize)
    根据ID 批量更新
    static <T> boolean
    updateById(T entity)
    根据 ID 选择修改

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 方法详细资料

    • save

      public static <T> boolean save(T entity)
      插入一条记录(选择字段,策略插入)
      参数:
      entity - 实体对象
    • saveBatch

      public static <T> boolean saveBatch(Collection<T> entityList)
      插入(批量)
      参数:
      entityList - 实体对象集合
    • saveBatch

      public static <T> boolean saveBatch(Collection<T> entityList, int batchSize)
      插入(批量)
      参数:
      entityList - 实体对象集合
      batchSize - 插入批次数量
    • saveOrUpdateBatch

      public static <T> boolean saveOrUpdateBatch(Collection<T> entityList)
      批量修改插入
      参数:
      entityList - 实体对象集合
    • saveOrUpdateBatch

      public static <T> boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize)
      批量修改插入
      参数:
      entityList - 实体对象集合
      batchSize - 每次的数量
    • removeById

      public static <T> boolean removeById(Serializable id, Class<T> entityClass)
      根据 ID 删除
      参数:
      id - 主键ID
      entityClass - 实体类
    • removeById

      public static <T> boolean removeById(T entity)
      根据实体(ID)删除
      参数:
      entity - 实体
    • remove

      public static <T> boolean remove(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      根据 entity 条件,删除记录
      参数:
      queryWrapper - 实体包装类 QueryWrapper
    • updateById

      public static <T> boolean updateById(T entity)
      根据 ID 选择修改
      参数:
      entity - 实体对象
    • update

      public static <T> boolean update(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> updateWrapper)
      根据 UpdateWrapper 条件,更新记录 需要设置sqlset
      参数:
      updateWrapper - 实体对象封装操作类 UpdateWrapper
    • update

      public static <T> boolean update(T entity, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> updateWrapper)
      根据 whereEntity 条件,更新记录
      参数:
      entity - 实体对象
      updateWrapper - 实体对象封装操作类 UpdateWrapper
    • updateBatchById

      public static <T> boolean updateBatchById(Collection<T> entityList)
      根据ID 批量更新
      参数:
      entityList - 实体对象集合
    • updateBatchById

      public static <T> boolean updateBatchById(Collection<T> entityList, int batchSize)
      根据ID 批量更新
      参数:
      entityList - 实体对象集合
      batchSize - 更新批次数量
    • removeByIds

      public static <T> boolean removeByIds(Collection<? extends Serializable> list, Class<T> entityClass)
      删除(根据ID 批量删除)
      参数:
      list - 主键ID或实体列表
      entityClass - 实体类
    • removeByMap

      public static <T> boolean removeByMap(Map<String,Object> columnMap, Class<T> entityClass)
      根据 columnMap 条件,删除记录
      参数:
      columnMap - 表字段 map 对象
      entityClass - 实体类
    • saveOrUpdate

      public static <T> boolean saveOrUpdate(T entity)
      TableId 注解存在更新记录,否插入一条记录
      参数:
      entity - 实体对象
    • getById

      public static <T> T getById(Serializable id, Class<T> entityClass)
      根据 ID 查询
      参数:
      id - 主键ID
      entityClass - 实体类
    • getOne

      public static <T> T getOne(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      根据 Wrapper,查询一条记录

      结果集,如果是多个会抛出异常,随机取一条加上限制条件 wrapper.last("LIMIT 1")

      参数:
      queryWrapper - 实体对象封装操作类 QueryWrapper
    • getOne

      public static <T> T getOne(T entity)
      根据 entity里不为空的字段,查询一条记录

      结果集,如果是多个会抛出异常,随机取一条加上限制条件 wrapper.last("LIMIT 1")

      参数:
      entity - 实体对象
    • getOne

      public static <T> T getOne(T entity, boolean throwEx)
      根据 entity里不为空的字段,查询一条记录
      参数:
      entity - 实体对象
      throwEx - 有多个 result 是否抛出异常
    • getOne

      public static <T> T getOne(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper, boolean throwEx)
      根据 Wrapper,查询一条记录
      参数:
      queryWrapper - 实体对象封装操作类 QueryWrapper
      throwEx - 有多个 result 是否抛出异常
    • listByMap

      public static <T> List<T> listByMap(Map<String,Object> columnMap, Class<T> entityClass)
      查询(根据 columnMap 条件)
      参数:
      columnMap - 表字段 map 对象
      entityClass - 实体类
    • listByIds

      public static <T> List<T> listByIds(Collection<? extends Serializable> idList, Class<T> entityClass)
      查询(根据ID 批量查询)
      参数:
      idList - 主键ID列表
      entityClass - 实体类
    • getMap

      public static <T> Map<String,Object> getMap(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      根据 Wrapper,查询一条记录
      参数:
      queryWrapper - 实体对象封装操作类 QueryWrapper
    • getMap

      public static <T> Map<String,Object> getMap(T entity)
      根据 entity不为空条件,查询一条记录
      参数:
      entity - 实体对象
    • count

      public static <T> long count(Class<T> entityClass)
      查询总记录数
      参数:
      entityClass - 实体类
      另请参阅:
      • Wrappers.emptyWrapper()
    • count

      public static <T> long count(T entity)
      根据entity中不为空的数据查询记录数
      参数:
      entity - 实体类
    • count

      public static <T> long count(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      根据 Wrapper 条件,查询总记录数
      参数:
      queryWrapper - 实体对象封装操作类 QueryWrapper
    • list

      public static <T> List<T> list(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      查询列表
      参数:
      queryWrapper - 实体对象封装操作类 QueryWrapper
    • list

      public static <T> List<T> list(com.baomidou.mybatisplus.core.metadata.IPage<T> page, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      类型参数:
      T - entity
      参数:
      page - 分页条件
      queryWrapper - 实体对象封装操作类 QueryWrapper
      返回:
      列表数据
    • list

      public static <T> List<T> list(Class<T> entityClass)
      查询所有
      参数:
      entityClass - 实体类
      另请参阅:
      • Wrappers.emptyWrapper()
    • list

      public static <T> List<T> list(com.baomidou.mybatisplus.core.metadata.IPage<T> page, Class<T> entityClass)
      类型参数:
      T - entity
      参数:
      page - 分页条件
      entityClass - 实体类
      返回:
      列表数据
      从以下版本开始:
      3.5.3.2
    • list

      public static <T> List<T> list(T entity)
      根据entity中不为空的字段进行查询
      参数:
      entity - 实体类
      另请参阅:
      • Wrappers.emptyWrapper()
    • list

      public static <T> List<T> list(com.baomidou.mybatisplus.core.metadata.IPage<T> page, T entity)
      根据entity中不为空的字段进行查询
      类型参数:
      T - entity
      参数:
      page - 分页条件
      entity - 实体类
      返回:
      列表数据
      从以下版本开始:
      3.5.3.2
    • listMaps

      public static <T> List<Map<String,Object>> listMaps(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      查询列表
      参数:
      queryWrapper - 实体对象封装操作类 QueryWrapper
    • listMaps

      public static <T> List<Map<String,Object>> listMaps(com.baomidou.mybatisplus.core.metadata.IPage<? extends Map<String,Object>> page, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      类型参数:
      T - entity
      参数:
      page - 分页参数
      queryWrapper - queryWrapper 实体对象封装操作类 QueryWrapper
      返回:
      列表数据
      从以下版本开始:
      3.5.3.2
    • listMaps

      public static <T> List<Map<String,Object>> listMaps(Class<T> entityClass)
      查询所有列表
      参数:
      entityClass - 实体类
      另请参阅:
      • Wrappers.emptyWrapper()
    • listMaps

      public static <T> List<Map<String,Object>> listMaps(com.baomidou.mybatisplus.core.metadata.IPage<? extends Map<String,Object>> page, Class<T> entityClass)
      分页查询列表
      类型参数:
      T - entity
      参数:
      page - 分页条件
      entityClass - 实体类
      返回:
      列表数据
      从以下版本开始:
      3.5.3.2
    • listMaps

      public static <T> List<Map<String,Object>> listMaps(T entity)
      根据entity不为空的条件查询列表
      参数:
      entity - 实体类
    • listMaps

      public static <T> List<Map<String,Object>> listMaps(com.baomidou.mybatisplus.core.metadata.IPage<? extends Map<String,Object>> page, T entity)
      根据entity不为空的条件查询列表
      类型参数:
      T - entity
      参数:
      page - 分页条件
      entity - entity
      返回:
      列表数据
      从以下版本开始:
      3.5.3.2
    • listObjs

      public static <T> List<T> listObjs(Class<T> entityClass)
      查询全部记录
      参数:
      entityClass - 实体类
    • listObjs

      public static <E, T> List<E> listObjs(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      根据 Wrapper 条件,查询全部记录
      参数:
      queryWrapper - 实体对象封装操作类 QueryWrapper
    • listObjs

      public static <T, V> List<V> listObjs(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper, com.baomidou.mybatisplus.core.toolkit.support.SFunction<? super T,V> mapper)
      根据 Wrapper 条件,查询全部记录
      参数:
      queryWrapper - 实体对象封装操作类 QueryWrapper
      mapper - 转换函数
    • listObjs

      public static <T, V> List<V> listObjs(Class<T> entityClass, com.baomidou.mybatisplus.core.toolkit.support.SFunction<? super T,V> mapper)
      查询全部记录
      参数:
      entityClass - 实体类
      mapper - 转换函数
    • pageMaps

      public static <T, E extends com.baomidou.mybatisplus.core.metadata.IPage<Map<String, Object>>> E pageMaps(E page, Class<T> entityClass)
      无条件翻页查询
      参数:
      page - 翻页对象
      entityClass - 实体类
      另请参阅:
      • Wrappers.emptyWrapper()
    • pageMaps

      public static <T, E extends com.baomidou.mybatisplus.core.metadata.IPage<Map<String, Object>>> E pageMaps(E page, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      翻页查询
      参数:
      page - 翻页对象
      queryWrapper - 实体对象封装操作类 QueryWrapper
    • page

      public static <T> com.baomidou.mybatisplus.core.metadata.IPage<T> page(com.baomidou.mybatisplus.core.metadata.IPage<T> page, Class<T> entityClass)
      无条件翻页查询
      参数:
      page - 翻页对象
      entityClass - 实体类
      另请参阅:
      • Wrappers.emptyWrapper()
    • page

      public static <T> com.baomidou.mybatisplus.core.metadata.IPage<T> page(com.baomidou.mybatisplus.core.metadata.IPage<T> page, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      翻页查询
      参数:
      page - 翻页对象
      queryWrapper - 实体对象封装操作类 QueryWrapper
    • query

      public static <T> QueryChainWrapper<T> query(Class<T> entityClass)
      链式查询 普通
      返回:
      QueryWrapper 的包装类
    • ktQuery

      public static <T> com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper<T> ktQuery(Class<T> entityClass)
      kt链式查询
      返回:
      KtQueryWrapper 的包装类
    • lambdaQuery

      public static <T> LambdaQueryChainWrapper<T> lambdaQuery(Class<T> entityClass)
      链式查询 lambda 式

      注意:不支持 Kotlin

      返回:
      LambdaQueryWrapper 的包装类
    • update

      public static <T> UpdateChainWrapper<T> update(Class<T> entityClass)
      链式更改 普通
      返回:
      UpdateWrapper 的包装类
    • ktUpdate

      public static <T> com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper<T> ktUpdate(Class<T> entityClass)
      kt链式更改
      返回:
      KtUpdateWrapper 的包装类
    • lambdaUpdate

      public static <T> LambdaUpdateChainWrapper<T> lambdaUpdate(Class<T> entityClass)
      链式更改 lambda 式

      注意:不支持 Kotlin

      返回:
      LambdaUpdateWrapper 的包装类
    • saveOrUpdate

      public static <T> boolean saveOrUpdate(T entity, com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> updateWrapper)

      根据updateWrapper尝试更新,否继续执行saveOrUpdate(T)方法 此次修改主要是减少了此项业务代码的代码量(存在性验证之后的saveOrUpdate操作)

      参数:
      entity - 实体对象
    • getObj

      public static <T, V> V getObj(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper, com.baomidou.mybatisplus.core.toolkit.support.SFunction<? super T,V> mapper)
      根据 Wrapper,查询一条记录
      参数:
      queryWrapper - 实体对象封装操作类 QueryWrapper
      mapper - 转换函数
    • getEntityClass

      protected static <T> Class<T> getEntityClass(Collection<T> entityList)
      从集合中获取实体类型
      类型参数:
      T - 实体类型
      参数:
      entityList - 实体集合
      返回:
      实体类型
    • getEntityClass

      protected static <T> Class<T> getEntityClass(com.baomidou.mybatisplus.core.conditions.AbstractWrapper<T,?,?> queryWrapper)
      从wrapper中尝试获取实体类型
      类型参数:
      T - 实体类型
      参数:
      queryWrapper - 条件构造器
      返回:
      实体类型
    • getEntityClass

      protected static <T> Class<T> getEntityClass(T entity)
      从entity中尝试获取实体类型
      类型参数:
      T - 实体类型
      参数:
      entity - 实体
      返回:
      实体类型
    • getTableInfo

      protected static <T> com.baomidou.mybatisplus.core.metadata.TableInfo getTableInfo(Class<T> entityClass)
      获取表信息,获取不到报错提示
      类型参数:
      T - 实体类型
      参数:
      entityClass - 实体类
      返回:
      对应表信息