在我的网站的UI上,我显示来自DB的信息,请使用“ spring”。我要制作,如果项目数量等于0,则隐藏此“ div”。如果项目数量大于0,则在html中显示“ div”,我从spring回来:
<div th:each="viewAvailableWhisky : ${viewAvailableWhisky}">
<div class="tilt pic" id="ShowHide">
<a th:href="@{~/buySelectedWhisky(nameBuyWhiskey=${viewAvailableWhisky.id})}" >
<img th:attr="src=${viewAvailableWhisky.photo}" id="photoId" width="150" height="250"/>
<div>
<b> <span th:text="${viewAvailableWhisky.nameWhisky}">Name</span></b>
</div>
<div>
<b> Quantity: <span th:text="${viewAvailableWhisky.quantityWhisky}"
>quantityWhisky</span>piece</b>
<input type="hidden" id="quantity" th:value="${viewAvailableWhisky.quantityWhisky}"/>
</div>
<div>
<b> $ <span th:text="${viewAvailableWhisky.price}">Price</span></b>
</div>
</a>
</div>
</div>
我认为,最好使用JS。但是我不知道如何,我尝试使用此代码。此代码无法从数据库中捕获每个项目的商品数量
$(document).ready ( function(){
var quantityItems = $("#quantity").val();
console.log(quantityItems);
if(quantityItems>0){
$("#ShowHide").show();
}
else {
$("#ShowHide").hide();
}
});
如果满足条件,则th:if =“ $ {condition}”属性用于显示视图的一部分。
<span th:if="${student.gender} == 'M'" th:text="Male" />
此外,如果不满足以下条件,则百里香提供了显示特定部分的选项:
<span th:unless="${student.gender} == 'M'" th:text="Female" />
(有关更多信息,请参阅本教程或Thymeleaf条件简介)
要仅在用户具有特定角色时显示某些内容,请使用Spring Security与thymeleaf的集成。
<div sec:authorize="hasRole('ROLE_ADMIN')">
This content is only shown to administrators.
</div>
有关Spring Security集成的更多信息,请参见此处。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句