昨天我下载了新的 Spring 3.1RC 来测试 Spring MVC 中刚刚引入的对 flash 作用域变量的支持。不幸的是我无法让它工作......
我有一个 HTML 表单,其中包含一些没有 spring:forms 标签的复选框。像这样的东西:
<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>
在 Flash 范围支持之前,我的带注释的控制器看起来像:
@RequestMapping(value = "/deleteaction", method = RequestMethod.POST, params={"delete"})
public String deleteItems(@RequestParam(value="itemId", required=false) String itemId[]) {
或者,我可以使用 anHttpServletRequest
而不是@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 范围变量?