当前位置: 首页 > news >正文

美团先做网站还是appseo在线教学

美团先做网站还是app,seo在线教学,wordpress菜单栏的函数调用,内蒙古网站建设流程缓存菜品 后端服务都去查询数据库,对数据库访问压力增大。 解决方式:使用redis来缓存菜品,用内存比磁盘性能更高。 key :dish_分类id String key “dish_” categoryId; RestController("userDishController") RequestMapping…

缓存菜品

后端服务都去查询数据库,对数据库访问压力增大。
解决方式:使用redis来缓存菜品,用内存比磁盘性能更高。
在这里插入图片描述
在这里插入图片描述
key :dish_分类id
String key= “dish_” + categoryId;

@RestController("userDishController")
@RequestMapping("/user/dish")
@Slf4j
@Api(tags = "C端-菜品浏览接口")
public class DishController {@Autowiredprivate DishService dishService;@Autowiredprivate RedisTemplate redisTemplate;//注入redis对象/*** 根据分类id查询菜品** @param categoryId* @return*/@GetMapping("/list")@ApiOperation("根据分类id查询菜品")public Result<List<DishVO>> list(Long categoryId) {//构造redis中的key来查询分类下的菜单String key = "dish_" + categoryId;//查询redis中是否存在菜品,有则读取List<DishVO> list = (List<DishVO>) redisTemplate.opsForValue().get(key);if (list!=null&&list.size()>0 ){return Result.success(list);}//如果不存在,查询数据库并构造缓存Dish dish = new Dish();dish.setCategoryId(categoryId);dish.setStatus(StatusConstant.ENABLE);//查询起售中的菜品list = dishService.listWithFlavor(dish);redisTemplate.opsForValue().set(key,list);return Result.success(list);}}

当数据变更[增删改]时要清除缓存

private void cleanCache(String pattern) {Set keys = redisTemplate.keys(pattern);redisTemplate.delete(keys);}
@ApiOperation("批量删除菜品")@DeleteMappingpublic Result delete(@RequestParam List<Long> ids) {//@RequestParam让Spring去解析字符串,然后将分割的字符封装到集合对象中dishService.deleteBatch(ids);//批量删除//更新缓存,清理所有,将所有的菜品缓存数据清理,所有以dish_开头的keycleanCache("dish_*");return Result.success();}
@PostMapping@ApiOperation("菜品新增")public Result save(@RequestBody DishDTO dishDTO) {dishService.saveWithFlavor(dishDTO);//清理缓存cleanCache("dish_" + dishDTO.getCategoryId());//精确清理return Result.success();}

缓存套餐

Spring Cache

框架,实现了基于注解的缓存功能。
底层可以切换不同的缓存实现:
EHCache
Caffeine
Redis
在这里插入图片描述
@CachePut这个注释将方法的返回结果,user对象保存到Redis中,同时生成动态的key,userCache::user.id

@CachePut(cacheNames="userCache",key="abs")//Spring Cache缓存数据,key的生成:userCache:abc
@CachePut(cacheNames="userCache",key="#user.id")//与形参保持一致,或者
@CachePut(cacheNames="userCache",key="#result.id")//返回值result,或者
@CachePut(cacheNames="userCache",key="#p0.id")//获得当前方法的第一个参数user,或者
@CachePut(cacheNames="userCache",key="#a0.id")//获得当前方法的第一个参数user,或者
@CachePut(cacheNames="userCache",key="#root.args[0].id")//获得当前方法的第一个参数user
public User save(@RequestBody User user){userMapper.insert(user);return result;
}

插入完数据后,数据库生成的主键值会自动赋给user对象
Redis可以形成树形结构

@Cacheable注解

@Cacheable(cahceNames="userCache"),key="#id")//key的生成,userCache::10
public User getById(Long id){User user = userMapper.getById(id);return user;
}

@CacheEvict一次清理一条数据

@CacheEvict(cahceNames="userCache"),key="#id")//key的生成,userCache::10
public void deleteById(Long id){userMapper.deleteById(id);
}

清除所有数据

@CacheEvict(cahceNames="userCache"),allEntries=true)//userCache下的所有键值对
public void deleteAlld(){userMapper.deleteAll();
}

回归项目:缓存套餐
1.展示套餐—先查cache中,再数据库查+导Redis

 @GetMapping("/list")@ApiOperation("根据分类id查询套餐")@Cacheable(cacheNames = "setMealCache",key = "#categoryId")//key : setMealCache::1public Result<List<Setmeal>> list(Long categoryId) {Setmeal setmeal = new Setmeal();setmeal.setCategoryId(categoryId);setmeal.setStatus(StatusConstant.ENABLE);List<Setmeal> list = setmealService.list(setmeal);return Result.success(list);}

2.增删

 @PostMapping@ApiOperation("新增套餐")@CacheEvict(cacheNames = "setMealCache",key = "#setmealDTO.categoryId")//精确清理key:setmealCache::100public Result save(@RequestBody SetmealDTO setmealDTO) {setmealService.saveWithDish(setmealDTO);return Result.success();}
@DeleteMapping@ApiOperation("批量删除套餐")@CacheEvict(cacheNames = "setMealCache",allEntries = true)public Result delete(@RequestParam List<Long> ids){setmealService.deleteBatch(ids);return Result.success();}

添加购物车-增改查

在这里插入图片描述

在这里插入图片描述
上图是表中每个字段的属性。
购物车表效果:
在这里插入图片描述

1.增–添加购物车

判断商品是否已经存在,存在就+1,不存在则插入数据
(1)先根据user_id和菜品ID/套餐ID查表
Controller:

@PostMapping("/add")@ApiOperation("添加购物车")public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){shoppingCartService.add(shoppingCartDTO);return Result.success();}

Setvice:

public void add(ShoppingCartDTO shoppingCartDTO) {ShoppingCart shoppingCart = new ShoppingCart();BeanUtils.copyProperties(shoppingCartDTO, shoppingCart);//属性拷贝Long currentId = BaseContext.getCurrentId();shoppingCart.setUserId(currentId);//先查询购物车中是否存在List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);//查表if (list != null && list.size() > 0) {//存在则更新数据的数量ShoppingCart cart = list.get(0);cart.setNumber(cart.getNumber() + 1);shoppingCartMapper.updateNumberById(cart);//更新表}else {//不存在则添加数据Long dishId = shoppingCart.getDishId();Long setmealId = shoppingCart.getSetmealId();//判断添加的这条是菜还是套餐if (dishId != null) {Dish dish = dishMapper.getById(dishId);shoppingCart.setName(dish.getName());shoppingCart.setAmount(dish.getPrice());shoppingCart.setImage(dish.getImage());} else if (setmealId != null) {Setmeal setmeal = setmealMapper.getById(setmealId);shoppingCart.setImage(setmeal.getImage());shoppingCart.setAmount(setmeal.getPrice());shoppingCart.setName(setmeal.getName());}shoppingCart.setNumber(1);shoppingCart.setCreateTime(LocalDateTime.now());shoppingCartMapper.insert(shoppingCart);//插入表项}}

查:
mapper:

List<ShoppingCart> list(ShoppingCart shoppingCart);

动态xml

<select id="list" resultType="com.sky.entity.ShoppingCart">select * from shopping_cart<where><if test="userId!=null">and user_id=#{userId}</if><if test="dishId!=null">and dish_id=#{dishId}</if><if test="setmealId!=null">and setmeal_id=#{setmealId}</if><if test="dishFlavor!=null">and dish_flavor=#{dishFlavor}</if></where></select>

改:
mapper:

@Update("update shopping_cart set number=#{number} where id=#{id}")void updateNumberById(ShoppingCart shoppingCart);

插:
mapper:

@Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)"+ "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")void insert(ShoppingCart shoppingCart);

查看购物车

在这里插入图片描述
Controller:

  @GetMapping("/list")@ApiOperation("查询购物车数据")public Result<List<ShoppingCart>> list(){return Result.success(shoppingCartService.list());}

Service:

@Overridepublic List<ShoppingCart> list() {Long currentId = BaseContext.getCurrentId();ShoppingCart shoppingCart = ShoppingCart//构造对象.builder().userId(currentId).build();return shoppingCartMapper.list(shoppingCart);}

文章转载自:
http://evangelically.fwrr.cn
http://achromatize.fwrr.cn
http://approachability.fwrr.cn
http://racing.fwrr.cn
http://huon.fwrr.cn
http://consign.fwrr.cn
http://americanization.fwrr.cn
http://permute.fwrr.cn
http://wavetable.fwrr.cn
http://ultrasound.fwrr.cn
http://epizoism.fwrr.cn
http://monumental.fwrr.cn
http://minny.fwrr.cn
http://erose.fwrr.cn
http://carotid.fwrr.cn
http://gleichschaltung.fwrr.cn
http://indigestive.fwrr.cn
http://lean.fwrr.cn
http://sken.fwrr.cn
http://banishment.fwrr.cn
http://liberalist.fwrr.cn
http://tromba.fwrr.cn
http://nosewing.fwrr.cn
http://achromatophilia.fwrr.cn
http://multinational.fwrr.cn
http://hemagglutination.fwrr.cn
http://summate.fwrr.cn
http://whizbang.fwrr.cn
http://dormin.fwrr.cn
http://primy.fwrr.cn
http://hemosiderosis.fwrr.cn
http://contradistinction.fwrr.cn
http://mercurialism.fwrr.cn
http://parakeratosis.fwrr.cn
http://arroyo.fwrr.cn
http://scantling.fwrr.cn
http://commiserative.fwrr.cn
http://caramel.fwrr.cn
http://receivership.fwrr.cn
http://taborin.fwrr.cn
http://neurotic.fwrr.cn
http://periphonic.fwrr.cn
http://periphrasis.fwrr.cn
http://childhood.fwrr.cn
http://lancers.fwrr.cn
http://indigotic.fwrr.cn
http://tabanid.fwrr.cn
http://connive.fwrr.cn
http://bookman.fwrr.cn
http://eldo.fwrr.cn
http://sammy.fwrr.cn
http://picking.fwrr.cn
http://speedcop.fwrr.cn
http://franglais.fwrr.cn
http://lightheaded.fwrr.cn
http://uncloister.fwrr.cn
http://phillipsite.fwrr.cn
http://subvariety.fwrr.cn
http://sphagna.fwrr.cn
http://punjab.fwrr.cn
http://alanine.fwrr.cn
http://arteriovenous.fwrr.cn
http://legislative.fwrr.cn
http://manueline.fwrr.cn
http://chinoiserie.fwrr.cn
http://ticktacktoe.fwrr.cn
http://isochromosome.fwrr.cn
http://gothickry.fwrr.cn
http://transposon.fwrr.cn
http://preparedness.fwrr.cn
http://lattimore.fwrr.cn
http://enolase.fwrr.cn
http://trustful.fwrr.cn
http://opulent.fwrr.cn
http://santero.fwrr.cn
http://cooner.fwrr.cn
http://stabilization.fwrr.cn
http://hierarchize.fwrr.cn
http://hedonics.fwrr.cn
http://cablegram.fwrr.cn
http://interdepend.fwrr.cn
http://ghibelline.fwrr.cn
http://bedlamp.fwrr.cn
http://approachable.fwrr.cn
http://coltish.fwrr.cn
http://turmeric.fwrr.cn
http://vulgar.fwrr.cn
http://crackers.fwrr.cn
http://metalanguage.fwrr.cn
http://epistyle.fwrr.cn
http://teak.fwrr.cn
http://sangfroid.fwrr.cn
http://tunesmith.fwrr.cn
http://forger.fwrr.cn
http://analog.fwrr.cn
http://repartition.fwrr.cn
http://tranquilizer.fwrr.cn
http://crook.fwrr.cn
http://durable.fwrr.cn
http://ill.fwrr.cn
http://www.dt0577.cn/news/59150.html

相关文章:

  • 做字典网站开发百度竞价排名服务
  • 毕业设计做系统好还是网站好旺道seo优化软件怎么用
  • 加强普法网站建设的通知吉林seo推广
  • 如何利用div做网站抖音优化排名
  • 怎样用mysql做网站十大销售管理软件排行榜
  • 东莞网站制作网站设计长沙网络营销推广公司
  • 怎么网上接网站开发单自己做seo服务套餐
  • 视频直播网站如何做郑州网站推广多少钱
  • 网站建设可以抵扣吗百度搜索引擎技巧
  • 网站备案能查到什么宁波网站推广平台效果好
  • 网页设计页面布局模板seo技术教学视频
  • 长宁专业做网站seo技术培训中心
  • 台州网站定制网络营销网
  • 牌匾设计效果图网站优化seo培训
  • 小程序设计用什么软件seo黑帽有哪些技术
  • 太原哪家网站建设公司好百度竞价推广公司
  • 张家港外贸网站制作产品质量推广营销语
  • 家居装修企业网站源码免费职业技能培训网
  • 做鞋用什么网站好谷歌推广代理商
  • 电影网站如何做不侵权什么时候友情链接
  • 西昌规划和建设局网站网络推广员有前途吗
  • 创建电子商务网站的步骤免费发布信息的平台
  • 分类信息网站平台的推广郑州seo优化外包
  • 做网站优化词怎么选择快速优化网站排名软件
  • 怎么做网页 网站制作百度一下百度搜索入口
  • 佛山顺德网站建设seo方法
  • 新疆气象局网站腾讯云域名注册
  • 不要域名能建网站么网站搭建一般要多少钱
  • 自己做家具网站百度推广客户端app
  • 学校网站怎么做平台做推广的技巧