昨天我下載了新的Spring 3.1RC來測試Spring MVC中對flash範圍變量的剛剛引入的支持。不幸的是,我無法使它工作...我有一個HTML表單,其中包含一些沒有彈簧的複選框:窗體標籤。事情是這樣的:Spring MVC FlashMap和RedirectAttributes請求映射
<form action="/deleteaction" method="post">
<input type="checkbox" name="itemId" value="1" />
<input type="checkbox" name="itemId" value="2" />
<input type="submit" name="delete" value="Delete items" />
</form>
閃光燈範圍支持之前,我的註解控制器看起來像:
@RequestMapping(value = "/deleteaction", method = RequestMethod.POST, params={"delete"})
public String deleteItems(@RequestParam(value="itemId", required=false) String itemId[]) {
或者,我可以使用的HttpServletRequest
代替@RequestParam
:
@RequestMapping(value = "/deleteaction", method = RequestMethod.POST, params={"delete"})
public String deleteItems(HttpServletRequest request) {
String itemIds[] = request.getParameterValues("itemId");
兩個方法工作正常。如果我嘗試添加RedirectAttributes
到方法的參數,Spring會拋出異常:
@RequestMapping(value = "/deleteaction", method = RequestMethod.POST, params={"delete"})
public String deleteItems(@RequestParam(value="itemId", required=false) String itemId[], RedirectAttributes redirectAttrs) {
登錄:
Oct 16, 2011 11:20:37 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/App] threw
exception [Request processing failed; nested exception is
java.lang.IllegalArgumentException: argument type mismatch] with root cause
java.lang.IllegalArgumentException: argument type mismatch
我在做什麼錯?如何獲得RedirectAttribues參數添加Flash範圍變量的地方?