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

网站建设的物流人工智能培训机构哪个好

网站建设的物流,人工智能培训机构哪个好,做网站建设跑业务,秦皇岛网站制作服务文章目录 1、确认下单#xff1a;购物车页面点击去结算1.1、在OrderController类中创建 trade 方法1.2、在CartController类中创建 checkedCartInfos1.3、CartServiceImpl 实现 checkedCartInfos的业务功能1.4、在service-cart-client模块下定义远程openFeign接口1.5、在SpzxO… 文章目录 1、确认下单购物车页面点击去结算1.1、在OrderController类中创建 trade 方法1.2、在CartController类中创建 checkedCartInfos1.3、CartServiceImpl 实现 checkedCartInfos的业务功能1.4、在service-cart-client模块下定义远程openFeign接口1.5、在SpzxOrderApplication类上加上EnableFeignClients1.6、OrderServiceImpl 实现 trade的业务逻辑1.7、此时启动 SpzxOrderApplication 2、 openFeign拦截器使用2.1、使用feign拦截器拦截请求获取token重新传递token2.1.1、CartClientInterceptor2.1.2、EnableCartClientConfig2.1.3、SpzxOrderApplication 1、确认下单购物车页面点击去结算 点击去结算这个按钮会发起一个请求这个请求是trade然后展示我们要购买的商品和商品的总金额 1.1、在OrderController类中创建 trade 方法 RestController Tag(name 订单管理模块, description 订单管理模块) RequestMapping(/api/order/orderInfo) public class OrderController {Resourceprivate OrderService orderService;//查询购物车中选中的购物项列表 转为 orderItem 列表交给前端展示Operation(summary 确认下单购物车页面点击去结算)GetMapping(/auth/trade)public Result trade() {TradeVo tradeVo orderService.trade();return Result.ok(tradeVo);} }1.2、在CartController类中创建 checkedCartInfos RestController RequestMapping(/api/order/cart) Tag(name 购物车模块) public class CartController {//只要请求头中携带token不需要再传用户idOperation(summary 查询用户购物车已选中购物项列表)GetMapping(/auth/checkedCartInfos)public Result checkedCartInfos(){ListCartInfo cartInfos cartService.checkedCartInfos();return Result.ok(cartInfos);} }1.3、CartServiceImpl 实现 checkedCartInfos的业务功能 Service public class CartServiceImpl implements CartService {Resourceprivate RedisTemplate redisTemplate;private BoundHashOperations getUserCart() {UserInfo userInfo SpzxServiceAuthInterceptor.THREAD_LOCAL.get();BoundHashOperations ops redisTemplate.boundHashOps(spzx:cart: userInfo.getId());return ops;}Overridepublic ListCartInfo checkedCartInfos() {//泛型1redis键类型泛型2hash的key类型 泛型3hash的value的类型BoundHashOperationsString,String,CartInfo userCart getUserCart();return userCart.values().stream().filter(cartInfo - cartInfo.getIsChecked()1).toList();} }1.4、在service-cart-client模块下定义远程openFeign接口 FeignClient(value service-cart) public interface CartClient {GetMapping(/api/order/cart/auth/checkedCartInfos)public ResultListCartInfo checkedCartInfos();DeleteMapping(/api/order/cart/auth/delCheckedCartInfos)public ResultVoid delCheckedCartInfos(); } 1.5、在SpzxOrderApplication类上加上EnableFeignClients SpringBootApplication EnableSpzxServiceAuth EnableFeignClients(basePackages com.atguigu.spzx) EnableCartClientConfig MapperScan(basePackages com.atguigu.spzx.order.mapper) EnableTransactionManagement public class SpzxOrderApplication {public static void main(String[] args){SpringApplication.run(SpzxOrderApplication.class,args);} }1.6、OrderServiceImpl 实现 trade的业务逻辑 Service public class OrderServiceImpl extends ServiceImplOrderMapper, OrderInfo implements OrderService {Resourceprivate CartClient cartClient;Resourceprivate StringRedisTemplate stringRedisTemplate;Overridepublic TradeVo trade() {//1、查询 当前用户 的购物车中已选中的购物项列表(cart服务管理购物车数据)ResultListCartInfo cartInfos cartClient.checkedCartInfos();if (cartInfos.getCode() ! 200) {throw new SpzxException(ResultCodeEnum.FAIL,null);}ListCartInfo cartInfoList cartInfos.getData();if (CollectionUtils.isEmpty(cartInfoList)) {//没有已选中的购物项throw new SpzxException(ResultCodeEnum.FAIL,null);}Long token IdUtil.getSnowflake(1,1).nextId();//将token存到redisredis的大key问题stringRedisTemplate.opsForValue().set(spzx:order:token.toString(), 1, 30, TimeUnit.MINUTES);//2、将购物项列表转为 OrderItem列表ListOrderItem orderItemList cartInfoList.stream().map(cartInfo - {OrderItem orderItem new OrderItem();orderItem.setOrderId(token);orderItem.setSkuId(cartInfo.getSkuId());orderItem.setSkuName(cartInfo.getSkuName());orderItem.setSkuNum(cartInfo.getSkuNum());orderItem.setSkuPrice(cartInfo.getCartPrice());orderItem.setThumbImg(cartInfo.getImgUrl());return orderItem;}).toList();TradeVo tradeVo new TradeVo();tradeVo.setOrderItemList(orderItemList);//遍历每一个订单项计算它的小计金额返回//最后对所有小计金额累加 得到总金额tradeVo.setTotalAmount(orderItemList.stream().map(orderItem - {return orderItem.getSkuPrice().multiply(new java.math.BigDecimal(orderItem.getSkuNum()));}).reduce(BigDecimal::add).get());return tradeVo;} }1.7、此时启动 SpzxOrderApplication -点击 购物车页面的 去结算按钮 发现报错NullPointerException java.lang.NullPointerException: Cannot invoke com.atguigu.spzx.model.entity.user.UserInfo.getId() because the return value of com.atguigu.spzx.common.util.AuthContextUtil.getUserInfo() is nullat com.atguigu.spzx.cart.service.impl.CartServiceImpl.getAllCkecked(CartServiceImpl.java:147)2、 openFeign拦截器使用 2.1、使用feign拦截器拦截请求获取token重新传递token 针对service-cart微服务是获取不到当前登录用户的信息。原因service-order微服务调用service-cart微服务的时候是通过openFeign进行调用openFeign在调用的时候会丢失请求头 2.1.1、CartClientInterceptor Component public class CartClientInterceptor implements RequestInterceptor {Overridepublic void apply(RequestTemplate requestTemplate) {//1、获取引入cartClient模块的 项目 在使用cartClient时 请求报文中的tokenServletRequestAttributes requestAttributes (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();HttpServletRequest request requestAttributes.getRequest();String token request.getHeader(token);//2、将token设置到feign客户端的请求报文中requestTemplate.header(token, token);} }现在订单服务无法使用feign拦截器因为这个组件类放到了com.atguigu.spzx.cart.interceptor下面订单服务扫描不到如果我们想启用它可以创建注解然后把注解加到订单服务的启动类上面 2.1.2、EnableCartClientConfig Target({ElementType.TYPE}) Retention(java.lang.annotation.RetentionPolicy.RUNTIME) Documented Import(value {CartClientInterceptor.class}) public interface EnableCartClientConfig { }2.1.3、SpzxOrderApplication SpringBootApplication EnableSpzxServiceAuth EnableFeignClients(basePackages com.atguigu.spzx) EnableCartClientConfig MapperScan(basePackages com.atguigu.spzx.order.mapper) EnableTransactionManagement public class SpzxOrderApplication {public static void main(String[] args){SpringApplication.run(SpzxOrderApplication.class,args);} }
http://www.w-s-a.com/news/944303/

相关文章:

  • 浑南区建设局网站永州网站建设公司推荐
  • 做外贸都得有网站吗绵阳网站建设制作
  • 功能性的网站建设北京餐饮品牌设计公司
  • php做网站优势视频直播软件
  • 怎么安装php网站哪个网站是专门为建设方服务的
  • 重慶网站开发sina app engine wordpress
  • wampserver网站开发步骤中冠工程管理咨询有限公司
  • 自己做网站商城需要营业执照吗老外做牛排的视频网站
  • 网站推广效果的评估指标主要包括公司广告推广
  • 昆明网站建设那家好哪个网站学做凉皮
  • hype做网站动效哪里有给网站做
  • 打扑克网站推广软件设计类专业哪个最好
  • 网站设计首页网站建设意向书
  • 做网站要学那些angularjs后台管理系统网站
  • 广州白云手机网站建设学做点心上哪个网站
  • 哈尔滨网站建设步骤百度青岛代理公司
  • 怎么利用代码做网站军队 网站备案
  • 百度手机版网址免费广州seo
  • 军博做网站公司wordpress评论插件
  • 如何申请一个网站 做视频网站报错解析
  • 徐州高端网站建设无锡找做网站
  • 网站如何不需要备案百度的宣传视频广告
  • 如何用易语言做网站采购系统有哪些
  • 建一个网站容易吗浙江省城乡建设厅官网
  • 奇点网站建设黄骅贴吧百度贴吧
  • 站长爱it如何分析网站设计
  • 服装公司网站定位seo网站关键词
  • 电商网站开发流程文档南京 seo 价格
  • 网站建设任务分解张家港网站制作服务
  • 化州+网站建设网络营销怎么做推广