资讯动态

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

发布时间:2026/9/10 18:30:21 来源:尧图企业网站定制
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);}}

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价