Spring MVC:作为GET@RequestParam的复杂对象
2022-08-31 05:36:13
假设我有一个列出表格上对象的页面,我需要放一个表单来过滤表格。过滤器作为Ajax GET发送到这样的URL: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,) { ... }
可能吗?我该怎么做?