新闻详情

新闻详情

首页 / 资讯中心 / 详情

[redis]黑马点评-商铺类型缓存

发布时间:2026/6/16 17:37:42
[redis]黑马点评-商铺类型缓存
Redis-P37-商城类型缓存接口开发ShopTypeControllerGetMapping(list)publicResultqueryTypeList(){returntypeService.queryList();}IShopTypeServicepublicinterfaceIShopTypeServiceextendsIServiceShopType{ResultqueryList();}ShopTypeServiceImplServicepublicclassShopTypeServiceImplextendsServiceImplShopTypeMapper,ShopTypeimplementsIShopTypeService{ResourceprivateStringRedisTemplatestringRedisTemplate;OverridepublicResultqueryList(){StringkeyCACHE_TYPE_LIST;//从redis中查询类型缓存StringtypeJsonstringRedisTemplate.opsForValue().get(key);if(StrUtil.isNotBlank(typeJson)){//存在,直接返回ListShopTypeshopTypeListJSONUtil.toList(typeJson,ShopType.class);returnResult.ok(shopTypeList);}//为空,查询数据库ListShopTypeshopTypeListquery().orderByAsc(sort).list();//将数据库信息转为str保存到缓存stringRedisTemplate.opsForValue().set(key,JSONUtil.toJsonStr(shopTypeList));returnResult.ok(shopTypeList);}}
网站建设 高端定制 企业官网