title: Spring Data JPA Use SpEL syntax to conditionally build query
body: <p>I tried to build a query depending on a boolean @Param, and the difficulty is that I build the end of the query without using a classical operator ( = , &lt;, > ...). </p>
  
  <p>For the example, let's assume I want to fetch all my Sales objects that are not related to an Account object (if I pass false in @Param) or that are related to an Account (if I pass true in the @Param) : </p>
  
  <pre><code>@Query("SELECT sale .... 
   WHERE sale.account :#{isbound ? NOT NULL : IS NULL}")
  public List&lt;Sale&gt; getSales(@Param("isbound") boolean isBound);
  </code></pre>
  
  <p>I tried a few syntaxs based on the official Spring documentation (<a href="https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions" rel="nofollow noreferrer">https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions</a>), but all their examples are working with an operator before the expression, like this:  entity = #{the_expression}.</p>
  
  <p>Does somebody once tried this and can give me the good way to write this ? thx !</p>