假设我有一个列出表中对象的页面,并且我需要放置一个表格来过滤表。过滤器以Ajax GET的形式发送到如下网址:http : //foo.com/system/controller/action?page=1&prop1= x& prop2=y&prop3=z
而不是像我的控制器上那样有很多参数:
@RequestMapping(value = "/action")
public @ResponseBody List<MyObject> myAction(
@RequestParam(value = "page", required = false) int page,
@RequestParam(value = "prop1", required = false) String prop1,
@RequestParam(value = "prop2", required = false) String prop2,
@RequestParam(value = "prop3", required = false) String prop3) { ... }
并假设我的MyObject为:
public class MyObject {
private String prop1;
private String prop2;
private String prop3;
//Getters and setters
...
}
我想做类似的事情:
@RequestMapping(value = "/action")
public @ResponseBody List<MyObject> myAction(
@RequestParam(value = "page", required = false) int page,
@RequestParam(value = "myObject", required = false) MyObject myObject,) { ... }
可能吗?我怎样才能做到这一点?
@ModelAttribute
。只需在Google上搜索“ Spring MVC表单处理 ”,您将获得大量的教程/示例。但请确保使用现代的表单处理方式,即Spring v2.5 +