1

我的 JSP 中有一个 Spring 表单标记,并且模型绑定到它。我希望表单内的一些输入作为单个 @RequestParam 值接收,但是无论我输入 Spring 输入还是纯 HTML 输入,值都会绑定到模型。我怎样才能摆脱这种行为?

4

1 回答 1

2

Simply put this inside your spring form:

<input type="text" id="yourParam" name="yourParam" value="3"/>

and you will be able to get the value in your controller with @RequestParam without binding it to your model:

 @RequestMapping(value = "/yourMapping", method = RequestMethod.POST)
 public ModelAndView showForm(@RequestParam String yourParam, YourModelObject yourModelObject...) {
     // You can retrieve here the value of your JSP input

 }
于 2012-08-22T17:36:40.577 回答