I would like to know how controller methods should interact with ModelAttribute annotated methods.
For example handlePage method would like to filter the list created by createList method?
Or set the id for the object created by createAnObject method?
Is it possible or ModelAttribute annotated methods are designed to attach static data to the model?
@ModelAttribute("someList")
public ArrayList<SomeList> createList() {
return new ArrayList<SomeList>(100);
}
@ModelAttribute("anObject")
public AnObject createAnObject() {
return new MyObject();
}
@RequestMapping(method=RequestMethod.GET)
public v开发者_如何学Pythonoid handlePage(Model model) {
//Do some stuff to populate the model....
}
The two shouldn't really interact. @ModelAttribute, in this context, is intended for exposure of reference data, i.e. data that doesn't depend on the details of the request.
If your handler method needs to modify that data, then @ModelAttribute isn't appropriate. Instead, the handler method should explicitly add the data to the model after modifying it.
加载中,请稍侯......
精彩评论