How to have multiple condition in an th:if tag using thymeleaf

I got the answer from the thymeleaf forum. The way to do it is :

th:if="${evaluation < 49 and evaluation > 29}"

Problem solved !


This is what worked for me:

th:if="${evaluation lt 49 and evaluation gt 29}"

In my opinion, a better and more maintainable solution could be to write the evaluation code in a proper class.

class Evaluator{

private int value;
....

public boolean isBounded() {
    return value < 49 && value > 29;
}

then in thymeleaf, call the function:

<p th:if="${evaluator.isBounded()} ...

Some benefits:

  1. Cleaner template.
  2. Control in java code.
  3. Isolation. More complex evaluations could be written without changing the template.

I hope this helps.