看段代码
/**
* 添加商品到购物车
*
* @return
*/
@GetMapping("/addToCart")
public String addToCart(@RequestParam("skuId") Long skuId,
@RequestParam("num") Integer num,
Model model) throws ExecutionException, InterruptedException {
cartService.addToCart(skuId, num);
model.addAttribute("skuId", skuId);
return "redirect:/addToCartSuccess.html";
}
/**
* 跳转到成功页
*
* @param skuId
* @param model
* @return
*/
@GetMapping("/addToCartSuccess.html")
public String addToCartSuccessPage(@RequestParam("skuId") Long skuId, Model model) {
//重定向到成功页面。再次查询购物车数据即可
CartItem item = cartService.getCartItem(skuId);
model.addAttribute("item", item);
return "success";
}
跳转之后model的的item数据无法获取。
使用RedirectAttributes re
ra.addFlashAttribute(); 将数据放在session里面可以取出,但是只能取出一次。
@GetMapping("/addToCart")
public String addToCart(@RequestParam("skuId") Long skuId,
@RequestParam("num") Integer num,
RedirectAttributes ra) throws ExecutionException, InterruptedException {
cartService.addToCart(skuId, num);
ra.addAttribute("skuId", skuId);
return "redirect:http://cart.mall.com/addToCartSuccess.html";
}