Java SpringMVC将属性重定向到WS异常。如何修复?
我正在使用Spring4.0.3 我的控制器如下所示:-Java SpringMVC将属性重定向到WS异常。如何修复?,java,spring-mvc,Java,Spring Mvc,我正在使用Spring4.0.3 我的控制器如下所示:- @RequestMapping(value="/delete/{id}", method=RequestMethod.GET) public ModelAndView deleteUser(@PathVariable Integer id, final RedirectAttributes redirectAttributes) throws ShopNotFound { ModelAndView mav = n
@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;
}
所以我所有的代码都很好,除了重定向属性。我阅读了有关它的内容,并找到了代码示例。但我仍然无法在测试代码中使用它。请告诉我出了什么事
例外情况:-
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
使用redirectAttributes.addFlashAttribute(“成功消息”,“用户已成功删除”);我希望它能帮助你:)