簡體   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