title: Why not use @RequestParam instead of @ModelAttribute
body: <p>In a a POST request handling method (annotated with <code>@RequestMapping</code>) of a Spring MVC controller, you can access the form values POST-ed from the form in two ways (correct?).</p>
  
  <h2>Use <code>@ModelAttribute</code></h2>
  
  <p>You can use a model object (command) class that bundles all the form values together and use an argument annotated <code>@Valid</code> <code>@ModelAttribute</code>to pass in the form values. This seems to be the common way of processing forms.</p>
  
  <pre><code> @RequestMapping(value = { "thing/{thing}/part/" }, method = RequestMethod.POST)
   public String processForm(
      @PathVariable("thing") final String thing,
      @ModelAttribute(value = "command") @Valid final Command command,
      final BindingResult bindingResult) {
      if (!bindingResult.hasErrors()) {
         final String name = command.getName();
         final long time = command.getTime().getTime();
  
         // Process the form
  
         return "redirect:" + location;
      } else {
         return "form";
      }
   }
  </code></pre>
  
  <h2>Use <code>@RequestParam</code>.</h2>
  
  <p>You can annotate individual  method arguments with <code>@RequestParam</code>.</p>
  
  <pre><code> @RequestMapping(value = { "thing/{thing}/part/" }, method = RequestMethod.POST)
   public String processForm(
         @PathVariable("thing") final String thing,
         @RequestParam(value = "name", required=true) final String name,
         @RequestParam(value = "time", required=true) final Date time,
        final HttpServletResponse response) {
      // Process the form
  
      return "redirect:" + location;
   }
  </code></pre>
  
  <h2>Why Use <code>@ModelAttribute</code></h2>
  
  <p>So why bother using <code>@ModelAttribute</code>, given that it has the inconvenience of having to create an auxiliary command  class? What are the limitations of using a <code>@RequestParam</code>.</p>