问题
the code shows below
the Users value from @Modelattribute is boolean an how to set this condition
<div th:each="s: ${Users}">
<div th:if="${s == true" >
<header th:include="../templates/SellerTemplate :: header" id="header">
</header>
</div>
<div th:if="${s != true}" >
<header th:include="../templates/homeTemplate :: header" id="header">
</header>
</div>
</div>
the @Modelattribue
public boolean users ;
@ModelAttribute("Users")
public boolean getloggeduser() {
if(securityDAO.getLoggedUserAccount()!= null) {
users=true;
}
else{
users=false;
}
return users;
}
the main problem is how to set the attribute value to th:each or any other statement are available? please share your answer
回答1:
I believe that you are looking for something like this:
<div th:if="${Users == true}" >
<header th:include="../templates/SellerTemplate :: header" id="header">
</header>
</div>
<div th:if="${Users == false}" >
<header th:include="../templates/homeTemplate :: header" id="header">
</header>
</div>
You should only use th:each
for lists or arrays, there is no point using it for other types.
来源:https://stackoverflow.com/questions/23903277/how-to-set-modelattribute-boolean-value-inside-html