2

I am trying to print some html when a choose / when condition is met like this:

 <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

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

有谁知道发生了什么?

4

1 回答 1

5

采用

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

代替

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

按照您键入它的方式,该test属性被评估为一个字符串: 的评估结果和 的评估结果的${notification.placeId}串联。==${place.placeId}

您希望将整个事物作为布尔表达式进行评估。

于 2012-11-28T22:02:05.983 回答