5

How do I do the conditional operator like this in thymeleaf?

Ex: condiction ? result1 : result2 

1 Answer 1

7

Looks like it's just...

<tr th:class="${row.even}? 'even' : 'odd'"> ... </tr> <tr th:class="${row.even}? (${row.first}? 'first' : 'even') : 'odd'"> ... </tr> <tr th:class="${row.even}? 'alt'"> ... </tr> 
Sign up to request clarification or add additional context in comments.

1 Comment

You can also keep them all in the expression, which I prefer. Like this: th:class="${row.even ? 'even' : 'odd'}"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.