Instead of @RequestParam , which is associated with a single form value, you can use the @ModelAttribute annotation and bind to the entire object. But it should be used in conjunction with form or bind Spring JSTL.
Example: - the controller that invokes the JSP page must add objects to the model:
@RequestMapping(value="/uploadForm", method=RequestMethod.GET)
public String showUploadForm (model model) {
Artist artist = new Artist(); Track track = new Track(); model.addAttribute("artist", artist); model.addAttribute("track", track); return "uploadForm";
}
- JSP might look something like this:
Name of the track *:
The controller processing the form submission;
@RequestMapping (value = "/ uploadToServer", method = RequestMethod.POST)
public String uploadToServer (@ModelAttribute ("artist") Artist, @ModelAttribute (track) Track track) {....}
Here I found a good explanation for using @ModelAttribute annotation - krams915.blogspot.ca
source share