Class BaseService<M extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T>, T>

java.lang.Object
com.baomidou.mybatisplus.extension.repository.AbstractRepository<M,T>
com.baomidou.mybatisplus.extension.repository.CrudRepository<M,T>
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<M,T>
com.codeupsoft.base.service.BaseService<M,T>
Type Parameters:
M - Mapper接口类型
T - 实体类型
All Implemented Interfaces:
com.baomidou.mybatisplus.extension.repository.IRepository<T>, com.baomidou.mybatisplus.extension.service.IService<T>

public class BaseService<M extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T>, T> extends com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<M,T>
业务服务基类.

所有业务Service都应该继承此类,提供统一的CRUD操作和通用业务方法. 基于MyBatis-Plus的ServiceImpl,自动拥有常用的数据库操作方法.

Author:
Liu,Dongdong
  • Field Summary

    Fields inherited from class com.baomidou.mybatisplus.extension.repository.CrudRepository

    baseMapper

    Fields inherited from class com.baomidou.mybatisplus.extension.repository.AbstractRepository

    log

    Fields inherited from interface com.baomidou.mybatisplus.extension.repository.IRepository

    DEFAULT_BATCH_SIZE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    根据ID查询,如不存在则抛出业务异常.
    根据ID查询,返回Optional包装.
    oneOrThrow(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<T> wrapper, String message)
    按条件查询单条,如不存在则抛出业务异常.
    com.codeupsoft.base.common.domain.PageResult<T>
    pageList(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<T> wrapper, com.baomidou.mybatisplus.core.toolkit.support.SFunction<T,?> orderColumn, boolean asc)
    分页查询(支持单字段排序)并返回标准列表响应.
    com.codeupsoft.base.common.domain.PageResult<T>
    pageList(com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper)
    通用分页查询并返回标准列表响应.
    void
    批量根据ID删除,如失败则抛出业务异常.
    void
    根据ID删除,如失败则抛出业务异常.
    void
    saveBatchOrThrow(Collection<T> entities, String message)
    批量保存,如失败则抛出业务异常.
    void
    saveOrThrow(T entity, String message)
    保存实体,如失败则抛出业务异常.
    void
    批量保存或更新,如失败则抛出业务异常(事务).
    void
    批量按ID更新,如失败则抛出业务异常.
    void
    updateByIdOrThrow(T entity, String message)
    根据ID更新,如失败则抛出业务异常.

    Methods inherited from class com.baomidou.mybatisplus.extension.repository.CrudRepository

    getBaseMapper, getSqlStatement, saveBatch, saveOrUpdateBatch, updateBatchById

    Methods inherited from class com.baomidou.mybatisplus.extension.repository.AbstractRepository

    executeBatch, executeBatch, getEntityClass, getMap, getMapperClass, getObj, getOne, getOneOpt, getSqlSessionFactory, removeById, saveOrUpdate

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.baomidou.mybatisplus.extension.repository.IRepository

    count, count, exists, getBaseMapper, getById, getEntityClass, getMap, getObj, getOne, getOne, getOneOpt, getOneOpt, getOptById, ktQuery, ktUpdate, lambdaQuery, lambdaQuery, lambdaUpdate, list, list, list, list, listByIds, listByMap, listMaps, listMaps, listMaps, listMaps, listObjs, listObjs, listObjs, listObjs, page, page, pageMaps, pageMaps, query, remove, removeById, removeById, removeById, removeByIds, removeByIds, removeByMap, save, saveBatch, saveOrUpdate, saveOrUpdateBatch, update, update, update, updateBatchById, updateById

    Methods inherited from interface com.baomidou.mybatisplus.extension.service.IService

    removeBatchByIds, saveBatch, saveOrUpdateBatch, updateBatchById
  • Constructor Details

    • BaseService

      public BaseService()
  • Method Details

    • pageList

      public com.codeupsoft.base.common.domain.PageResult<T> pageList(com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper)
      通用分页查询并返回标准列表响应.
      Parameters:
      queryWrapper - 查询条件
      Returns:
      标准列表响应
    • getByIdOrThrow

      public T getByIdOrThrow(Serializable id, String message)
      根据ID查询,如不存在则抛出业务异常.
      Parameters:
      id - 主键ID
      message - 不存在时的提示消息
      Returns:
      实体
    • getOptionalById

      public Optional<T> getOptionalById(Serializable id)
      根据ID查询,返回Optional包装.
      Parameters:
      id - 主键ID
      Returns:
      Optional实体
    • oneOrThrow

      public T oneOrThrow(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<T> wrapper, String message)
      按条件查询单条,如不存在则抛出业务异常.
      Parameters:
      wrapper - 查询条件
      message - 不存在时的提示消息
      Returns:
      实体
    • updateByIdOrThrow

      public void updateByIdOrThrow(T entity, String message)
      根据ID更新,如失败则抛出业务异常.
    • removeByIdOrThrow

      @Transactional(rollbackFor=Exception.class) public void removeByIdOrThrow(Serializable id, String message)
      根据ID删除,如失败则抛出业务异常.
    • saveOrThrow

      public void saveOrThrow(T entity, String message)
      保存实体,如失败则抛出业务异常.
    • saveBatchOrThrow

      @Transactional(rollbackFor=Exception.class) public void saveBatchOrThrow(Collection<T> entities, String message)
      批量保存,如失败则抛出业务异常.
    • updateBatchByIdOrThrow

      @Transactional(rollbackFor=Exception.class) public void updateBatchByIdOrThrow(Collection<T> entities, String message)
      批量按ID更新,如失败则抛出业务异常.
    • removeBatchByIdsOrThrow

      @Transactional(rollbackFor=Exception.class) public void removeBatchByIdsOrThrow(Collection<? extends Serializable> ids, String message)
      批量根据ID删除,如失败则抛出业务异常.
    • saveOrUpdateBatchOrThrow

      @Transactional(rollbackFor=Exception.class) public void saveOrUpdateBatchOrThrow(Collection<T> entities, String message)
      批量保存或更新,如失败则抛出业务异常(事务).
    • pageList

      public com.codeupsoft.base.common.domain.PageResult<T> pageList(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<T> wrapper, com.baomidou.mybatisplus.core.toolkit.support.SFunction<T,?> orderColumn, boolean asc)
      分页查询(支持单字段排序)并返回标准列表响应.