thymeleaf - boolean condition check in Thymleaf is not working
问题描述
I am using Spring boot and Thymleaf in my application.I am sending a CommonResponse model from backend to view and in that model there is a property "isLoggedIn" which is a boolean value and i am using that value to add a style like this
<li class="nav-item hide-on-scroll" id="sign_in_menu" th:style="${commonResponse.isLoggedIn == false ? '' : 'display:none'} ">
<a class="nav-link" data-toggle="modal" data-target="#loginModal">Sign in</a>
</li>
when i run this gives me a error
"Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "commonResponse.isLoggedIn == false ? '' : 'display:none'"
It happens when "isLoogedIn" property is part of this model "CommonResponse".but if i pass this as a standalone property it works fine
<li class="nav-item hide-on-scroll" id="sign_in_menu" th:style="${isLoggedIn == false ? '' : 'display:none'} ">
<a class="nav-link" data-toggle="modal" data-target="#loginModal">Sign in</a>
</li>
What is the issue?
解决方案
请尝试以下操作
<li class="nav-item hide-on-scroll" id="sign_in_menu" th:style="${commonResponse.isLoggedIn} ? '' : 'display:none' ">
<a class="nav-link" data-toggle="modal" data-target="#loginModal">Sign in</a>
</li>
推荐阅读
- vue.js - vue 没有显示正确的信息
- r - 格式化闪亮的 Plotly 子图 - 单个标题和图形大小
- r - 按 ID 和日期进行子抽样
- jhipster - 在 JHipster v6.4.1 中,我可以在哪里放置新角色以授权访问他们的帐户设置?
- cocoa - 在目标内容偏移处停止 NSScrollView?
- gcc - 为什么升级到最新的 gcc 后找不到 libgfortran.so.5?
- python - 如何创建二维列表?
- ruby-on-rails - 在 CSV 中用双引号写入字符串的问题
- c# - ssis 脚本任务向多个收件人发送电子邮件
- spring-cloud-stream - SCDF Stream 保持“正在部署”状态