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

自己做的网站怎么链接火车头采集中国建筑协会官网

自己做的网站怎么链接火车头采集,中国建筑协会官网,做购物网站实例代码,南通网站建设规划书缓存菜品 后端服务都去查询数据库#xff0c;对数据库访问压力增大。 解决方式#xff1a;使用redis来缓存菜品#xff0c;用内存比磁盘性能更高。 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 ResultListDishVO list(Long categoryId) {//构造redis中的key来查询分类下的菜单String key dish_ categoryId;//查询redis中是否存在菜品有则读取ListDishVO list (ListDishVO) redisTemplate.opsForValue().get(key);if (list!nulllist.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 ListLong ids) {//RequestParam让Spring去解析字符串然后将分割的字符封装到集合对象中dishService.deleteBatch(ids);//批量删除//更新缓存清理所有将所有的菜品缓存数据清理所有以dish_开头的keycleanCache(dish_*);return Result.success();}PostMappingApiOperation(菜品新增)public Result save(RequestBody DishDTO dishDTO) {dishService.saveWithFlavor(dishDTO);//清理缓存cleanCache(dish_ dishDTO.getCategoryId());//精确清理return Result.success();}缓存套餐 Spring Cache 框架实现了基于注解的缓存功能。 底层可以切换不同的缓存实现 EHCache Caffeine Redis CachePut这个注释将方法的返回结果user对象保存到Redis中同时生成动态的keyuserCache::user.id CachePut(cacheNamesuserCache,keyabs)//Spring Cache缓存数据key的生成userCache:abc CachePut(cacheNamesuserCache,key#user.id)//与形参保持一致,或者 CachePut(cacheNamesuserCache,key#result.id)//返回值result,或者 CachePut(cacheNamesuserCache,key#p0.id)//获得当前方法的第一个参数user或者 CachePut(cacheNamesuserCache,key#a0.id)//获得当前方法的第一个参数user或者 CachePut(cacheNamesuserCache,key#root.args[0].id)//获得当前方法的第一个参数user public User save(RequestBody User user){userMapper.insert(user);return result; }插入完数据后数据库生成的主键值会自动赋给user对象 Redis可以形成树形结构 Cacheable注解 Cacheable(cahceNamesuserCache),key#id)//key的生成userCache::10 public User getById(Long id){User user userMapper.getById(id);return user; }CacheEvict一次清理一条数据 CacheEvict(cahceNamesuserCache),key#id)//key的生成userCache::10 public void deleteById(Long id){userMapper.deleteById(id); }清除所有数据 CacheEvict(cahceNamesuserCache),allEntriestrue)//userCache下的所有键值对 public void deleteAlld(){userMapper.deleteAll(); }回归项目缓存套餐 1.展示套餐—先查cache中再数据库查导Redis GetMapping(/list)ApiOperation(根据分类id查询套餐)Cacheable(cacheNames setMealCache,key #categoryId)//key : setMealCache::1public ResultListSetmeal list(Long categoryId) {Setmeal setmeal new Setmeal();setmeal.setCategoryId(categoryId);setmeal.setStatus(StatusConstant.ENABLE);ListSetmeal list setmealService.list(setmeal);return Result.success(list);}2.增删 PostMappingApiOperation(新增套餐)CacheEvict(cacheNames setMealCache,key #setmealDTO.categoryId)//精确清理key:setmealCache::100public Result save(RequestBody SetmealDTO setmealDTO) {setmealService.saveWithDish(setmealDTO);return Result.success();}DeleteMappingApiOperation(批量删除套餐)CacheEvict(cacheNames setMealCache,allEntries true)public Result delete(RequestParam ListLong 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);//先查询购物车中是否存在ListShoppingCart 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: ListShoppingCart list(ShoppingCart shoppingCart);动态xml select idlist resultTypecom.sky.entity.ShoppingCartselect * from shopping_cartwhereif testuserId!nulland user_id#{userId}/ifif testdishId!nulland dish_id#{dishId}/ifif testsetmealId!nulland setmeal_id#{setmealId}/ifif testdishFlavor!nulland 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 ResultListShoppingCart list(){return Result.success(shoppingCartService.list());}Service Overridepublic ListShoppingCart list() {Long currentId BaseContext.getCurrentId();ShoppingCart shoppingCart ShoppingCart//构造对象.builder().userId(currentId).build();return shoppingCartMapper.list(shoppingCart);}
http://www.dnsts.com.cn/news/85766.html

相关文章:

  • 文化馆门户网站建设的作用及意义网络职业有哪些
  • 沭阳住房和城乡建设局网站网站推广总结
  • 文化建设网站枣庄网页制作公司
  • 外贸建站哪个最便宜宁波市建设网
  • 自己做民宿在什么网站上投放新闻稿发布平台
  • 北方外贸网站建设外贸客户如何开发
  • 学网站制作多少钱wordpress微信登录调用
  • 4徐汇区网站建设如何设计制作企业网站
  • 狠狠做网站 百度一下深圳专业建网站公司排行
  • php就是做网站吗营销qq手机版
  • 网站开速度几秒湘乡网站seo
  • 百度云服务器搭建网站步骤深圳市住房和建设保障局
  • 网站建设总体流程投票制作网站
  • 快速网站收录wordpress注册模板
  • 图书馆网站建设请示东莞微信小程序开发公司报价
  • 展览网站建设昆山网站建设哪家比较好
  • 网站平台建设规划网页界面设计中常用的中英文字体有哪些
  • 高端大气网站设计欣赏郑州一建集团有限公司官网
  • 观澜小学 网站建设给wordpress菜单加图标
  • 在建设厅网站上下载资质标准市场推广方案范文
  • 官方网站建设成果做网站一般要多钱
  • 网站搜索查询深圳福田区网站建设
  • 网站模板设计开发简约好看的网站模板
  • youku网站开发技术网站改了模板被百度降权
  • 网站提交百度了经常修改网站网站建设手机端官网
  • 那些网站是vue做的传奇手游新开服网站
  • 静态网站开发软件页面设计要点
  • 外贸网站建设价格怎么样子目录网站
  • 做公司网站需要本地搭建网站
  • 轻博客网站开发深圳建设岗位证书报名网站