title: How to implement Spring Data Jpa Dynamic Query and Joint inquiry
body: <p>Current project I used Spring data jpa and spring boot, most time I found it's very convinence until meet this requirement, I found hard to deal. 
  That is I have Buyer Entity and Supplier Entity and the middle Entity(BuyerSupplier), if I'd like to search Buyer by phone or name or both or all, I have to supply many methods, like below:</p>
  
  <pre><code>if(phone!=null&amp;&amp;name!=null)
      List&lt;Buyer&gt; findByPhoneAndName(phone,name)
  else if(phone!=null)
      List&lt;Buyer&gt; findByPhone(phone)
  else if(name!=null)
      List&lt;Buyer&gt; findByName(name)
  else
      List&lt;Buyer&gt; findAll()
  </code></pre>
  
  <p>Obviously, above code is very bad.And actually, my business logic is more complex,  meantime I want to search buyer belong to a special Supplier and maybe a special status buyer. Corresponding sql like below:</p>
  
  <pre><code>select b.* from buyer b, buyer_supplier bs
  where b.id = bs.buyer_id
  and bs.supplier_id = 1
  and bs.stauts = 'Activated'
  and b.name like '%foo%'
  and b.phone like '%123%'
  </code></pre>
  
  <p>and I also want to build dynamic sql, like below:</p>
  
  <pre><code>select b.* from buyer b, buyer_supplier bs
  where b.id = bs.buyer_id
  if(name != null)
      and b.name like '%foo%'
  if(phone!=null)
      and b.phone like '%123%'
  if(supplierId&gt;0)
      and b.supplier_id = 1
  if(status!=null)
      and bs.stauts = 'Activated'
  </code></pre>
  
  <p>Could anyone give me some code sample or documents could teach me how to implement my above target? </p>