开发者

How does Spring encode POJOs in GET requests for @ModelAttribute?

I have a Spring MVC controller set up like so:

@RequestMapping("activityChart")
public ModelAndView activityChart(
  @RequestParam(required=false, value="parent") String parent,
  @RequestParam(required=false, value="expand") String[] expand,
  @ModelAttribute PaginationArgs paginationargs) throws IOException {

// ... return template renderer

}

Where PaginationArgs is a two-field POJO. I 开发者_StackOverflow中文版want to construct a URL string that includes values for paginationargs. It's easy to do for parent and expand - activityChart?parent=foo&expand=bar&expand=baz, but what's the right way to encode a POJO's fields?

JSP takes care of this in Spring with a <form:form modelAttribute='paginationargs'> tag, but our project isn't using JSP but Jamon instead.


In the simple case parameter names should be the same as the corresponding field names of the model object. So, if PaginationArgs has fields page and size, it would be like page=1&size=10.

In more complex cases Spring can accept parameters whose names are formed as described in 5.4 Bean manipulation and the BeanWrapper.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜