[英]Issue with Spring MVC Redirection
我在Spring重定向中遇到问题。 这是我第一次在Springs MVC 4.1中使用modelandview。 下面是代码片段
@RequestMapping(value="/delete/{id}",method=RequestMethod.GET)
private ModelAndView deleteProduct(@PathVariable Integer id,final RedirectAttributes redirectAttributes)
{
logger.info("Deleting product from database..."+id);
ModelAndView modelAndView = new ModelAndView("redirect:home");
redirectAttributes.addFlashAttribute( "message","Product was successfully deleted.");
return modelAndView;
}
它进入上述方法内部,并引发错误,指出客户端发送的请求在语法上不正确()。 (400错误代码)。 如果我删除重定向如下,它工作正常。 但是我需要重定向!
ModelAndView modelAndView = new ModelAndView("home");
首页映射代码
@RequestMapping(value="/home", method=RequestMethod.GET)
private ModelAndView home(@ModelAttribute Product product) {
return new ModelAndView("home");
}
但是下面的代码可以正常工作以进行重定向(其他功能)
@RequestMapping(value="/addproduct", method=RequestMethod.POST)
private ModelAndView addingProduct(@ModelAttribute Product product,final RedirectAttributes redirectAttributes) {
logger.info("Product adding to database...");
ModelAndView modelAndView = new ModelAndView("redirect:home");
redirectAttributes.addFlashAttribute( "message","Product was successfully added.");
return modelAndView;
}
请帮助我理解问题
尝试这种方式:
ModelAndView modelAndView = new ModelAndView("redirect:/home"); // from /delete/{id} Path
在使用ModelAndView modelAndView = new ModelAndView(“ redirect:/”);之后,它开始工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.