比较中列表的值
我需要循环遍历与数据库列相关的特定行列表,该列的类型为Integer
。数据库中的该列是同一表中父列 ID 的外键。
我必须匹配这两个值,如果匹配则在 JSP 中打印。
我已经浏览过此链接 Evaluate list.contains string in JSTL 并已一直在努力让它发挥作用。我不知道我到底错在哪里。
这是我到目前为止所得到的:
<c:forEach var="List" items="${Section.LangList}">
<c:if test="${List['Lang'] == List['Id']}">
...
</c:if>
</c:forEach>
这是我用来比较值的东西之一。我也尝试过 contains
和
。我缺少什么吗?
I need to loop over a particular list of rows pertaining to a database column, which is of type Integer
. This column in the database is the foreign key to the parent column ID in the same table.
I have to match the both these values and print in the JSP if there is a match.
I've gone through this link Evaluate list.contains string in JSTL and have been trying over to get it working. I don't know where exactly I've gone wrong.
Here is what I have so far:
<c:forEach var="List" items="${Section.LangList}">
<c:if test="${List['Lang'] == List['Id']}">
...
</c:if>
</c:forEach>
This is one of the things that I've used to compare the values. I've tried the contains
and the <c:set>
too. Is there something that I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要以小写字母开头的属性名称。
${Section.LangList}
不起作用,它必须是${Sections.langList}
。如果仍然不起作用,另一个可能的原因是双方的数据类型不同,即使它们包含相同的值。例如,
“42”
的String
值与42
的Integer
值相对应。您需要确保数据类型相同。与具体问题无关,您的命名约定很糟糕。
List
中的每一项肯定不是另一个List
,而很可能是Language
类。此外,不需要使用大括号表示法来访问具有固定名称的属性。只需使用${bean.property}
表示法即可。以下内容将使您的代码更符合命名约定并更加自文档化:我只是仍然想知道
${language.lang}
在这种情况下如何有意义。You need to start property names with lowercase. The
${Section.LangList}
won't work, it has to be${Sections.langList}
.If that still doesn't work, another possible cause is that the data type of the both sides is different, even though they contain the same value. E.g.
String
value of"42"
versusInteger
value of42
. You need to make sure that the data types are the same.Unrelated to the concrete problem, your naming convention is terrible. Each item of a
List<Language>
surely isn't anotherList
, but likely theLanguage
class. Also, using the brace notation to access a property with a fixed name is unnecessary. Just use the${bean.property}
notation. The following will make your code more conform naming conventions and more self-documenting:I only still wonder how
${language.lang}
makes sense in this context.尝试这样的事情:
如果它不起作用,请向我们展示您在迭代列表中的类
try something like this:
if it wont work show us you class that is on iterated list