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" 后面没有表名的问题。
| 限定符和类型 | 字段和说明 |
|---|---|
protected M |
mapper |
DEFAULT_BATCH_SIZE| 构造器和说明 |
|---|
CacheableServiceImpl() |
| 限定符和类型 | 方法和说明 |
|---|---|
BaseMapper<T> |
getMapper() |
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 CacheableServiceImpl()
public boolean saveOrUpdate(T entity)
saveOrUpdate 在接口中 IService<T>public QueryWrapper query()
获取默认的 QueryWrapper。
使用 QueryWrapper.create() 构建默认查询条件的时候,
要使用 QueryWrapper.from(String...) 方法指定从哪个表
查询数据,不然使用 QueryWrapper.toSQL() 生成的
SQL 语句就是 "SELECT * FROM",没有表名信息。
默认通过反射获取表名,建议重写,根据情况设置默认表名,以提升效率。
例如:
{@codequery 在接口中 IService<T>QueryWrapperCopyright © 2025. All rights reserved.