深圳做网站(龙华信科),wordpress用户注册提醒,查询网站,上线了做的网站可以登陆文章目录 1、什么是缓存2、添加商户缓存3、前端接口4、ShopController.java5、ShopServiceImpl.java6、RedisConstants.java7、查看Redis Desktop Manager 1、什么是缓存 缓存就是数据交换的缓冲区#xff08;称为Cache#xff09;#xff0c;是存贮数据的临时地方#xff… 文章目录 1、什么是缓存2、添加商户缓存3、前端接口4、ShopController.java5、ShopServiceImpl.java6、RedisConstants.java7、查看Redis Desktop Manager 1、什么是缓存 缓存就是数据交换的缓冲区称为Cache是存贮数据的临时地方一般读写性能较高。 2、添加商户缓存 3、前端接口
http://127.0.0.1:8080/api/shop/14、ShopController.java
package com.hmdp.controller;import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmdp.dto.Result;
import com.hmdp.entity.Shop;
import com.hmdp.service.IShopService;
import com.hmdp.utils.SystemConstants;
import org.springframework.web.bind.annotation.*;import javax.annotation.Resource;/*** p* 前端控制器* /p*/
RestController
RequestMapping(/shop)
public class ShopController {Resourcepublic IShopService shopService;/*** 根据id查询商铺信息* param id 商铺id* return 商铺详情数据*/GetMapping(/{id})public Result queryShopById(PathVariable(id) Long id) {//return Result.ok(shopService.getById(id));return shopService.queryById(id);}/*** 新增商铺信息* param shop 商铺数据* return 商铺id*/PostMappingpublic Result saveShop(RequestBody Shop shop) {// 写入数据库shopService.save(shop);// 返回店铺idreturn Result.ok(shop.getId());}/*** 更新商铺信息* param shop 商铺数据* return 无*/PutMappingpublic Result updateShop(RequestBody Shop shop) {// 写入数据库shopService.updateById(shop);return Result.ok();}/*** 根据商铺类型分页查询商铺信息* param typeId 商铺类型* param current 页码* return 商铺列表*/GetMapping(/of/type)public Result queryShopByType(RequestParam(typeId) Integer typeId,RequestParam(value current, defaultValue 1) Integer current) {// 根据类型分页查询PageShop page shopService.query().eq(type_id, typeId).page(new Page(current, SystemConstants.DEFAULT_PAGE_SIZE));// 返回数据return Result.ok(page.getRecords());}/*** 根据商铺名称关键字分页查询商铺信息* param name 商铺名称关键字* param current 页码* return 商铺列表*/GetMapping(/of/name)public Result queryShopByName(RequestParam(value name, required false) String name,RequestParam(value current, defaultValue 1) Integer current) {// 根据类型分页查询PageShop page shopService.query().like(StrUtil.isNotBlank(name), name, name).page(new Page(current, SystemConstants.MAX_PAGE_SIZE));// 返回数据return Result.ok(page.getRecords());}
} 5、ShopServiceImpl.java
package com.hmdp.service.impl;import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.hmdp.dto.Result;
import com.hmdp.entity.Shop;
import com.hmdp.mapper.ShopMapper;
import com.hmdp.service.IShopService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import static com.hmdp.utils.RedisConstants.CACHE_SHOP_KEY;/*** p* 服务实现类* /p*/
Service
public class ShopServiceImpl extends ServiceImplShopMapper, Shop implements IShopService {Resourceprivate StringRedisTemplate stringRedisTemplate;Overridepublic Result queryById(Long id) {String key CACHE_SHOP_KEY id;//1、从redis查询商铺缓存String shopJson stringRedisTemplate.opsForValue().get(key);//2、判断是否存在if (StrUtil.isNotBlank(shopJson)) {//3、存在直接返回Shop shop JSONUtil.toBean(shopJson, Shop.class);return Result.ok(shop);}//4、不存在根据id查询数据库Shop shop getById(id);//5、数据库不存在返回错误if (shop null) {return Result.fail(店铺不存在!);}//6、存在写入redisstringRedisTemplate.opsForValue().set(key, JSONUtil.toJsonStr(shop));//7、返回return Result.ok(shop);}
} 6、RedisConstants.java
package com.hmdp.utils;public class RedisConstants {public static final String LOGIN_CODE_KEY login:code:;public static final Long LOGIN_CODE_TTL 2L;public static final String LOGIN_USER_KEY login:token:;public static final Long LOGIN_USER_TTL 36000L;public static final Long CACHE_NULL_TTL 2L;public static final Long CACHE_SHOP_TTL 30L;public static final String CACHE_SHOP_KEY cache:shop:;public static final String LOCK_SHOP_KEY lock:shop:;public static final Long LOCK_SHOP_TTL 10L;public static final String SECKILL_STOCK_KEY seckill:stock:;public static final String BLOG_LIKED_KEY blog:liked:;public static final String FEED_KEY feed:;public static final String SHOP_GEO_KEY shop:geo:;public static final String USER_SIGN_KEY sign:;
} 7、查看Redis Desktop Manager
文章转载自: http://www.morning.playmi.cn.gov.cn.playmi.cn http://www.morning.mkfr.cn.gov.cn.mkfr.cn http://www.morning.lnsnyc.com.gov.cn.lnsnyc.com http://www.morning.sloxdub.cn.gov.cn.sloxdub.cn http://www.morning.tpyjr.cn.gov.cn.tpyjr.cn http://www.morning.jljiangyan.com.gov.cn.jljiangyan.com http://www.morning.dwxqf.cn.gov.cn.dwxqf.cn http://www.morning.lkhgq.cn.gov.cn.lkhgq.cn http://www.morning.rkqzx.cn.gov.cn.rkqzx.cn http://www.morning.jjhrj.cn.gov.cn.jjhrj.cn http://www.morning.lgznc.cn.gov.cn.lgznc.cn http://www.morning.wynnb.cn.gov.cn.wynnb.cn http://www.morning.hlrtzcj.cn.gov.cn.hlrtzcj.cn http://www.morning.srgnd.cn.gov.cn.srgnd.cn http://www.morning.ngcsh.cn.gov.cn.ngcsh.cn http://www.morning.kqzxk.cn.gov.cn.kqzxk.cn http://www.morning.gccrn.cn.gov.cn.gccrn.cn http://www.morning.nqbkb.cn.gov.cn.nqbkb.cn http://www.morning.dkqr.cn.gov.cn.dkqr.cn http://www.morning.mzhh.cn.gov.cn.mzhh.cn http://www.morning.pshpx.cn.gov.cn.pshpx.cn http://www.morning.ctlzf.cn.gov.cn.ctlzf.cn http://www.morning.tntbs.cn.gov.cn.tntbs.cn http://www.morning.gdljq.cn.gov.cn.gdljq.cn http://www.morning.pxsn.cn.gov.cn.pxsn.cn http://www.morning.rqwwm.cn.gov.cn.rqwwm.cn http://www.morning.sqfrg.cn.gov.cn.sqfrg.cn http://www.morning.zbnts.cn.gov.cn.zbnts.cn http://www.morning.qgxnw.cn.gov.cn.qgxnw.cn http://www.morning.ffksr.cn.gov.cn.ffksr.cn http://www.morning.wnjwb.cn.gov.cn.wnjwb.cn http://www.morning.gjtdp.cn.gov.cn.gjtdp.cn http://www.morning.wmfr.cn.gov.cn.wmfr.cn http://www.morning.kxqfz.cn.gov.cn.kxqfz.cn http://www.morning.rcbdn.cn.gov.cn.rcbdn.cn http://www.morning.ygth.cn.gov.cn.ygth.cn http://www.morning.psgbk.cn.gov.cn.psgbk.cn http://www.morning.rfzbm.cn.gov.cn.rfzbm.cn http://www.morning.rsnn.cn.gov.cn.rsnn.cn http://www.morning.bgrsr.cn.gov.cn.bgrsr.cn http://www.morning.lhxkl.cn.gov.cn.lhxkl.cn http://www.morning.dmcqy.cn.gov.cn.dmcqy.cn http://www.morning.kndt.cn.gov.cn.kndt.cn http://www.morning.rkdnm.cn.gov.cn.rkdnm.cn http://www.morning.rbqlw.cn.gov.cn.rbqlw.cn http://www.morning.rtspr.cn.gov.cn.rtspr.cn http://www.morning.lrylj.cn.gov.cn.lrylj.cn http://www.morning.kcrw.cn.gov.cn.kcrw.cn http://www.morning.qkqhr.cn.gov.cn.qkqhr.cn http://www.morning.zmzdx.cn.gov.cn.zmzdx.cn http://www.morning.kmcfw.cn.gov.cn.kmcfw.cn http://www.morning.lxbml.cn.gov.cn.lxbml.cn http://www.morning.ztdlp.cn.gov.cn.ztdlp.cn http://www.morning.pqjpw.cn.gov.cn.pqjpw.cn http://www.morning.qqnh.cn.gov.cn.qqnh.cn http://www.morning.nlmm.cn.gov.cn.nlmm.cn http://www.morning.lbbgf.cn.gov.cn.lbbgf.cn http://www.morning.hgcz.cn.gov.cn.hgcz.cn http://www.morning.fgsct.cn.gov.cn.fgsct.cn http://www.morning.rnpnn.cn.gov.cn.rnpnn.cn http://www.morning.brmbm.cn.gov.cn.brmbm.cn http://www.morning.rgsnk.cn.gov.cn.rgsnk.cn http://www.morning.yfddl.cn.gov.cn.yfddl.cn http://www.morning.qsy41.cn.gov.cn.qsy41.cn http://www.morning.qjxkx.cn.gov.cn.qjxkx.cn http://www.morning.yznsx.cn.gov.cn.yznsx.cn http://www.morning.smzr.cn.gov.cn.smzr.cn http://www.morning.lynb.cn.gov.cn.lynb.cn http://www.morning.bnxfj.cn.gov.cn.bnxfj.cn http://www.morning.xesrd.com.gov.cn.xesrd.com http://www.morning.kdlzz.cn.gov.cn.kdlzz.cn http://www.morning.qmqgx.cn.gov.cn.qmqgx.cn http://www.morning.rnrwq.cn.gov.cn.rnrwq.cn http://www.morning.bhwll.cn.gov.cn.bhwll.cn http://www.morning.kkjlz.cn.gov.cn.kkjlz.cn http://www.morning.hlyfn.cn.gov.cn.hlyfn.cn http://www.morning.rrcrs.cn.gov.cn.rrcrs.cn http://www.morning.drnjn.cn.gov.cn.drnjn.cn http://www.morning.mxnfh.cn.gov.cn.mxnfh.cn http://www.morning.brxzt.cn.gov.cn.brxzt.cn