Java Spring MVC重定向问题

Java Spring MVC重定向问题,java,spring,spring-mvc,Java,Spring,Spring Mvc,我在春天面临一个问题。这是我第一次在SpringMVC4.1中使用modelandview。下面是代码片段 @RequestMapping(value="/delete/{id}",method=RequestMethod.GET) private ModelAndView deleteProduct(@PathVariable Integer id,final RedirectAttributes redirectAttributes) { logger.inf

我在春天面临一个问题。这是我第一次在SpringMVC4.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");
    }
但是下面的代码对于重定向(其他功能)工作正常

请帮助我理解这个问题

请尝试以下方法:

ModelAndView modelAndView = new ModelAndView("redirect:/home"); // from /delete/{id} Path

它在使用ModelAndView ModelAndView=new ModelAndView(“重定向:/”)后工作

看看我的答案,也许对你有帮助。
ModelAndView modelAndView = new ModelAndView("redirect:/home"); // from /delete/{id} Path