如何比较 JSTL 中的参数
我有数据库中的 ID 列表,并将它们在请求中传递给 servlet,但我无法将它们与任何数字进行比较。
我想也许我必须将它们转换为整数类型:
<c:forEach items="${subjec.id}" var="x">
${x}
</c:forEach>
<c:forEach items="${listPage}" var = "list">
${list.id}
<c:choose>
<c:when test="${list.id} == 1">
</c:when>
</c:choose>
</c:forEach>
<c:if test="${subject1.id == 1}">
${subject1.id}
</c:if>
但是,我无法基于整数格式进行测试。对于这个案例有什么建议吗?
I have list of ID's from a database and pass them in a request to a servlet, but i can't compare them to any number.
I think maybe i have to convert them to integer type:
<c:forEach items="${subjec.id}" var="x">
${x}
</c:forEach>
<c:forEach items="${listPage}" var = "list">
${list.id}
<c:choose>
<c:when test="${list.id} == 1">
</c:when>
</c:choose>
</c:forEach>
<c:if test="${subject1.id == 1}">
${subject1.id}
</c:if>
However, I cant test based on Integer format. Any suggetions for this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是错误的。您需要将整个表达式放入
${}
内。如果
getId()
返回Number
(整数、长整型等),然后使用以下内容:或者如果它返回
String
(顺便说一下,这是不自然的),然后使用以下内容:或者如果它返回一个
boolean
(仅作为示例),然后使用以下内容:This is wrong. You need to put the entire expression inside
${}
.If
getId()
returns aNumber
(integer, long, etc), then use the following:Or if it returns a
String
(which is unnatural by the way), then use the following:Or if it returns a
boolean
(just as an example), then use the following:它应该是
如果使用
将会抛出异常it should be
<c:when test="${list.id == '1'}">
if you use
<c:when test='${list.id == "1"}'>
exception will be thrown尝试
try