繁体   English   中英

Spring MVC RedirectAttributes thews异常。 怎么修?

[英]Spring mvc RedirectAttributes thews exception. How to fix?

我正在使用Spring 4.0.3。

我的控制器如下:

@RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
public ModelAndView deleteUser(@PathVariable Integer id,
        final RedirectAttributes redirectAttributes) throws ShopNotFound {

    ModelAndView mav = new ModelAndView("userIndex");       
    userDao.delete(id);;
    String message = "The user was successfully deleted.";
    return mav;
}

如果我按以下方式更改代码,则它可以按预期工作:-

@RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
public ModelAndView deleteUser(@PathVariable Integer id) throws ShopNotFound {

    ModelAndView mav = new ModelAndView("userIndex");       
    userDao.delete(id);;
    String message = "The user was successfully deleted.";
    return mav;
}

因此,除了RedirectAttributes之外,我所有的代码都很好。 我读了一下,发现代码也是如此。 但是我仍然无法在我的测试代码中使用它。 请告诉我出了什么问题。

Excepiton:-

HTTP状态500-请求处理失败; 嵌套异常是org.springframework.web.bind.annotation.support.HandlerMethodInvocationException:无法调用处理程序方法[public org.springframework.web.servlet.ModelAndView com.fnx.reg.controller.UserController.deleteUser(java.lang.Integer ,org.springframework.web.servlet.mvc.support.RedirectAttributes)抛出com.fnx.reg.exception.ShopNotFound]; 嵌套异常是java.lang.IllegalStateException:参数[RedirectAttributes]的类型为Model或Map,但不能从实际模型中分配。 您可能需要切换较新的MVC基础结构类才能使用此参数。

由于您的方法的返回类型正在使用ModelandView。
请参阅下面的2链接以解决此问题。

https://jira.spring.io/browse/SPR-9418

https://jira.spring.io/browse/SPR-8968

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM