title: Check preconditions in Controller or Service layer
body: <p>I'm using Google's Preconditions class to validate user's input data.<br>
  But I'm worried about where is the best point of checking user's input data using Preconditions class.<br>
  First, I wrote validation check code in Controller like below:  </p>
  
  <pre><code>@Controller
  ...
  public void register(ProductInfo data) {
      Preconditions.checkArgument(StringUtils.hasText(data.getName()),
          "Empty name parameter.");
      productService.register(data);
  }
  
  @Service
  ...
  public void register(ProductInfo data) {
      productDao.register(data);
  }
  </code></pre>
  
  <p>But I thought that <code>register</code> method in Service layer would be using another Controller method like below:  </p>
  
  <pre><code>@Controller
  ...
  public void register(ProductInfo data) {
      productService.register(data);
  }
  public void anotherRegister(ProductInfo data) {
      productService.register(data);
  }
  
  @Service 
  ...
  public void register(ProductInfo data) {
      Preconditions.checkArgument(StringUtils.hasText(data.getName()),
          "Empty name parameter.");
      productDao.register(data);
  }
  </code></pre>
  
  <p>On the other hand, the method of service layer would be used in just one controller.<br>
  I was confused. Which is the better way of checking preconditions in controller or service?<br>
  Thanks in advance.  </p>