【问题标题】:how to set @modelattribute boolean value inside html如何在html中设置@modelattribute布尔值
【发布时间】:2014-07-17 04:25:21
【问题描述】:

代码如下所示

@Modelattribute 中的用户值是布尔值以及如何设置此条件

 <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>

@Modelattribue

public boolean users ;
@ModelAttribute("Users")
public boolean getloggeduser() {
 if(securityDAO.getLoggedUserAccount()!= null) { 
    users=true;
     }
 else{ 
     users=false;
 } 
    return users;
}

主要问题是如何将属性值设置为th:each 或任何其他语句可用?请分享你的答案

【问题讨论】:

    标签: java html thymeleaf modelattribute


    【解决方案1】:

    我相信您正在寻找这样的东西:

    <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> 
    

    你应该只对列表或数组使用th:each,对其他类型没有意义。

    【讨论】:

    • here th:if="${s == true}" s 值来自 where 或 s 赋值 where
    • 还有一个问题,当用户注销时,模型属性中的布尔值没有改变
    • 这是一个完全不同的问题,可能与您使用 Spring Security 的方式有关
    猜你喜欢
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 2019-11-09
    • 2015-03-28
    • 1970-01-01
    相关资源
    最近更新 更多