public class CacheableServiceImpl<M extends BaseMapper<T>,T> extends Object implements IService<T>
可缓存数据的 Service 实现类。
该实现类对缓存做了以下处理:
saveOrUpdate(Object) 方法,分别调用 IService.save(Object) 和 IService.updateById(Object)
方法,避免缓存无法更新造成数据不一致。
query() 方法,解决使用 QueryWrapper.toSQL() 作为缓存
的主键时,"SELECT * FROM" 后面没有表名的问题。
| Modifier and Type | Field and Description |
|---|---|
protected M |
mapper |
DEFAULT_BATCH_SIZE| Constructor and Description |
|---|
CacheableServiceImpl() |
| Modifier and Type | Method and Description |
|---|---|
BaseMapper<T> |
getMapper()
获取对应实体类(Entity)的基础映射类(BaseMapper)。
|
QueryWrapper |
query()
获取默认的
QueryWrapper。 |
boolean |
saveOrUpdate(T entity)
保存或者更新实体类对象数据。
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcount, count, count, exists, exists, getByEntityIdOpt, getById, getByIdOpt, getObj, getObjAs, getObjAsOpt, getObjOpt, getOne, getOne, getOneAs, getOneAsOpt, getOneByEntityId, getOneOpt, getOneOpt, list, list, list, listAs, listByIds, listByMap, objList, objListAs, page, page, page, pageAs, queryChain, remove, remove, removeById, removeById, removeByIds, removeByMap, save, saveBatch, saveBatch, saveOrUpdateBatch, saveOrUpdateBatch, update, update, update, updateBatch, updateBatch, updateBatch, updateBatch, updateById, updateById, updateChain@Autowired protected M extends BaseMapper<T> mapper
public BaseMapper<T> getMapper()
获取对应实体类(Entity)的基础映射类(BaseMapper)。
public boolean saveOrUpdate(T entity)
保存或者更新实体类对象数据。
saveOrUpdate in interface IService<T>entity - 实体类对象true 保存或更新成功,false 保存或更新失败。public QueryWrapper query()
获取默认的 QueryWrapper。
使用 QueryWrapper.create() 构建默认查询条件的时候,
要使用 QueryWrapper.from(String...) 方法指定从哪个表
查询数据,不然使用 QueryWrapper.toSQL() 生成的
SQL 语句就是 "SELECT * FROM",没有表名信息。
默认通过反射获取表名,建议重写,根据情况设置默认表名,以提升效率。
例如:
{@codequery in interface IService<T>QueryWrapperCopyright © 2024. All rights reserved.