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
baseMapperFields inherited from class com.baomidou.mybatisplus.extension.repository.AbstractRepository
logFields inherited from interface com.baomidou.mybatisplus.extension.repository.IRepository
DEFAULT_BATCH_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetByIdOrThrow(Serializable id, String message) 根据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> 通用分页查询并返回标准列表响应.voidremoveBatchByIdsOrThrow(Collection<? extends Serializable> ids, String message) 批量根据ID删除,如失败则抛出业务异常.voidremoveByIdOrThrow(Serializable id, String message) 根据ID删除,如失败则抛出业务异常.voidsaveBatchOrThrow(Collection<T> entities, String message) 批量保存,如失败则抛出业务异常.voidsaveOrThrow(T entity, String message) 保存实体,如失败则抛出业务异常.voidsaveOrUpdateBatchOrThrow(Collection<T> entities, String message) 批量保存或更新,如失败则抛出业务异常(事务).voidupdateBatchByIdOrThrow(Collection<T> entities, String message) 批量按ID更新,如失败则抛出业务异常.voidupdateByIdOrThrow(T entity, String message) 根据ID更新,如失败则抛出业务异常.Methods inherited from class com.baomidou.mybatisplus.extension.repository.CrudRepository
getBaseMapper, getSqlStatement, saveBatch, saveOrUpdateBatch, updateBatchByIdMethods inherited from class com.baomidou.mybatisplus.extension.repository.AbstractRepository
executeBatch, executeBatch, getEntityClass, getMap, getMapperClass, getObj, getOne, getOneOpt, getSqlSessionFactory, removeById, saveOrUpdateMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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, updateByIdMethods inherited from interface com.baomidou.mybatisplus.extension.service.IService
removeBatchByIds, saveBatch, saveOrUpdateBatch, updateBatchById
-
Constructor Details
-
BaseService
public BaseService()
-
-
Method Details
-
pageList
-
getByIdOrThrow
根据ID查询,如不存在则抛出业务异常.- Parameters:
id- 主键IDmessage- 不存在时的提示消息- Returns:
- 实体
-
getOptionalById
根据ID查询,返回Optional包装.- Parameters:
id- 主键ID- Returns:
- Optional实体
-
oneOrThrow
-
updateByIdOrThrow
-
removeByIdOrThrow
@Transactional(rollbackFor=Exception.class) public void removeByIdOrThrow(Serializable id, String message) 根据ID删除,如失败则抛出业务异常. -
saveOrThrow
-
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
-