how to set @modelattribute boolean value inside html

限于喜欢 提交于 2020-01-25 10:31:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!