如何消除jsp表达式语言中的重复值? [英] how to eliminate duplicate values in jsp expression language?
本文介绍了如何消除jsp表达式语言中的重复值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<c:forEach items="${listOfRoutes}" var = "route">
<option value="${route.source }" >${route.source }</option>
</c:forEach>
此处listOfRoutes包含Route(id,source,destination)对象. 在这里,我只想显示不同的来源. 如何做到这一点,请帮助我.
here the listOfRoutes contains Route(id,source,destination) objects. here i want to show only distinct sources. how to do this, plz help me.
推荐答案
您可以使用Set
通过迭代列表存储源,因为Set
不允许重复,然后在选项中使用Set
来填充源,请在下面的代码中查看.
You can use Set
to store source by iterating list because Set
doesnot allow duplicate then use Set
to populate source in the option, please have a look in below code.
<%
Set setSource = new HashSet();
for(Route route:listOfRoutes){
setSource.add(route.getSource());
}
%>
<c:forEach items="${setSource}" var = "source">
<option value="${source}" >${source}</option>
</c:forEach>
如果您希望选项具有排序值,请使用TreeSet
.
if you want options to have sorted values, then please use TreeSet
.
这篇关于如何消除jsp表达式语言中的重复值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文