title: Spring Web MVC - validate individual request params
body: <p>I'm running a webapp in Spring Web MVC 3.0 and I have a number of controller methods whose signatures are roughly as follows:</p>
  
  <pre><code>@RequestMapping(value = "/{level1}/{level2}/foo", method = RequestMethod.POST)
  public ModelAndView createFoo(@PathVariable long level1,
          @PathVariable long level2,
          @RequestParam("foo_name") String fooname,
          @RequestParam(value = "description", required = false) String description);
  </code></pre>
  
  <p>I'd like to add some validation - for example, <code>description</code> should be limited to a certain length or <code>fooname</code> should only contain certain characters. If this validation fails, I want to return a message to the user rather than just throw some unchecked exception (which would happen anyway if I let the data percolate down to the DAO layer). I'm aware of JSR303 but have not worked with it and don't quite understand how to apply it in a Spring context.</p>
  
  <p>From what I understand, another option would be to bind the <code>@RequestBody</code> to an entire domain object and add validation constraints there, but currently my code is set up to accept individual parameters as shown above.</p>
  
  <p>What is the most straightforward way to apply validation to input parameters using this approach?</p>