title: No Content in Spring Boot Rest
body: <p>How do I configure Spring Boot to return 204 in GET methods (typically findAll methods) when the method does not fetch records? I would not like to do treatment in each method, type the code below:</p>
  
  <pre><code>if(!result)
      return new ResponseEntity&lt;Void&gt;(HttpStatus.NO_CONTENT);
      return new ResponseEntity&lt;Void&gt;(HttpStatus.OK)
  </code></pre>
  
  <p>I'd like to transform this method:</p>
  
  <pre><code>@GetMapping
  public ResponseEntity&lt;?&gt; findAll(){
      List&lt;User&gt; result = service.findAll();
      return !result.isEmpty() ? 
              new ResponseEntity&lt;&gt;(result, HttpStatus.OK) : new ResponseEntity&lt;Void&gt;(HttpStatus.NO_CONTENT);
  }
  </code></pre>
  
  <p>In this one:</p>
  
  <pre><code>@GetMapping
  public List&lt;User&gt; findAll(){
      return service.findAll();
  }
  </code></pre>
  
  <p>If the result from <strong>findAll()</strong> is empty or null then my controller should return <strong>204</strong> instead of <strong>200</strong>.</p>