title: Conditions in Thymeleaf th:href parameter
body: <p>So I have an element in my Thymeleaf template which has a link looking like that:</p>
  
  <pre><code>th:href="@{'/search/'+${searchType}(parameter1=${parameter1}, ... parameter10=${parameter10})}"
  </code></pre>
  
  <p>According to the current implementation the <code>parameter1...10</code> can have values that I don't want to include in the <code>href</code>. For example, if it's id, it can be -1, which means that no id chosen, so this parameter have to be omitted to avoid clattering the url string, so instead of </p>
  
  <p><code>/search/type?parameter1=-1</code></p>
  
  <p>get just clean</p>
  
  <p><code>/search/type</code></p>
  
  <p>How this can be achieved?
  I tried this:</p>
  
  <pre><code>th:href="@{'/search/'+${searchType}((${parameter1}=='-1'?''parameter1=${parameter1}))}"
  </code></pre>
  
  <p>But this expression causes exception:</p>
  
  <blockquote>
    <p>org.thymeleaf.exceptions.TemplateProcessingException: Could not parse
    as expression:</p>
  </blockquote>
  
  <p>I tried this:</p>
  
  <pre><code>th:href="@{'/search/'+${searchType}(parameter1=(${parameter1}=='-1'?'':${parameter1}))}"
  </code></pre>
  
  <p>But then the result is still not acceptable:</p>
  
  <p><code>/search/type?parameter1=</code></p>
  
  <p>So what is the correct way to eliminate undesirable parameters from the url?</p>