我收到此消息"消息请求方法' POST'不支持
description请求的资源不允许使用指定的HTTP方法。 "
和
我的控制器方法是: -
@RequestMapping(value = "/addtocart/{id}", method = RequestMethod.GET)
public ModelAndView addToCart(@PathVariable("id") String id) {
log.debug("Starting of the method addToCart");
// get the product based on product id
Product product = productDAO.getProductBYID(id);
cart.setPrice(product.getPrice());
cart.setProductName(product.getName());
String loggedInUserid = (String) session.getAttribute("loggedInUserID");
if (loggedInUserid == null) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
loggedInUserid = auth.getName();
}
cart.setUserID(loggedInUserid);
//It is not required if you given default value while creating the table
cart.setStatus('N'); // Status is New. Once it is dispatched, we can
// changed to 'D'
//To get sequence number, you can do programmatically in DAOImpl
//myCart.setId(ThreadLocalRandom.current().nextLong(100, 1000000 + 1));
cartDAO.save(cart);
// return "redirect:/view/Home.jsp";
ModelAndView mv = new ModelAndView("redirect:/Home");
mv.addObject("successMessage", " Successfuly add the product to myCart");
log.debug("Ending of the method addToCart");
return mv;
}
答案 0 :(得分:1)
您正在使用RequestMethod.GET
addToCart
方法。
@RequestMapping(value = "/addtocart/{id}", method = RequestMethod.POST)
GET
请求来调用您的方法