How can I do the same with thymeleaf in Spring Boot? I just want to set a default attribute for the page if the one is missing Here is an example how I do this in JSP.
<c:set var="sortField" value="${(empty requestScope.sortField) ? 'categpry' : requestScope.sortField}"/>
CodePudding user response:
Considering that you need this into your html
template, then you can declare a variable as you want with the following expression
<div id="firstDiv" th:with="sortField= (${sortField} != null) ? ${sortField} : 'category'" >
...here you can access the var sortField
</div>
but as indicated the variable will be available only inside this block of html.