title: How to return error status and validation errors from this Spring MVC controller?
body: <p>I have an action method defined like this in one of my controllers:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public @ResponseBody Post create(@Valid Post post, BindingResult bindingResult) {
      if (bindingResult.hasErrors()) {
          // how to return an error status + error messages from here?
      } else {
          postRepository.persist(post);
          return post;
      }
  }
  </code></pre>
  
  <p>When the post is persisted successfully, I return the post back to the client. But when it has validation errors, I want to return an Error status code as well as all the validation error messages back to the client.</p>
  
  <p>What's the best way to do this?</p>