gpt4 book ai didi

jsp - jSTL if else choose/when not evaluating variables

转载 作者:行者123 更新时间:2023-12-02 22:21:42 26 4
gpt4 key购买 nike

我正在尝试在满足选择/满足条件时打印一些 html:

 <c:choose>
<c:when test="${notification.placeId} == ${place.placeId}">
${notification.name}
</c:when>
<c:otherwise>
placeId: ${place.placeId} - notplaceid: ${notification.placeId}
</c:otherwise>
</c:choose>

这会打印: placeId: 50 - notplaceid: 43 placeId: 50 - notplaceid: 47 placeId: 50 - notplaceid: 49 placeId: 50 - notplaceid: 50 placeId: 50 - notplaceid: 51 placeId : 50 - notplaceid: 51 placeId: 50 - notplaceid: 51 placeId: 50 - notplaceid: 51 placeId: 50 - notplaceid: 52 placeId: 50 - notplaceid: 53 placeId: 50 - notplaceid: 0 placeId: 50 - notplaceid: 0

这一切都从 otherwise 打印出来,从不打印 when 语句中的通知名称。从打印中可以看出,粗体输出显然满足 when 条件,应该打印通知名称。

有人知道这是怎么回事吗?

最佳答案

使用

<c:when test="${notification.placeId == place.placeId}">

代替

<c:when test="${notification.placeId} == ${place.placeId}">

按照您输入的方式,test 属性被评估为一个字符串:${notification.placeId} 评估结果的串联,==,以及${place.placeId}的求值结果。

你希望整个事情都被评估为一个 bool 表达式。

关于jsp - jSTL if else choose/when not evaluating variables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13615129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com