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 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
PaginationArgshas fieldspageandsize, it would be likepage=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.