spring - 如何使用 jSTL 比较 2 个值

标签 spring jsp jstl

我在 Controller 中有列表

List l=serviceClientServiceImpl.getSavedParents(clientId); 
uiModel.addAttribute("savedParents",l);
List<Parent> parentList = 
(List<Parent>) serviceClientServiceImpl.getParents("Parent",Long.valueOf(clientId)); 
uiModel.addAttribute("parentList", parentList);

我正在 jsp 中检索它,如下所示

<ul style="max-width: 300px;" class="nav nav-pills nav-stacked" id="menuId"> 
<c:forEach items="${parentList}" var="test"> 

<li ><a href="#" value="${test.id}-${test.category}" id="${parent.id}" onclick="return getQuestions(this);" > 
<input type="checkbox" value="${test.id}">${test.name }</a></li> 


</c:forEach> 
</ul> 
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 

<c:forEach items="${savedParents}" var="test1"> 
<ul style="max-width: 300px;" class="nav nav-pills nav-stacked"> 
<li class="active"><a href="#" value="${test1.id}" onclick="return getQuestions(this);"> 
<input type="checkbox" value="${test1.id}"></a></li> 

</ul> 
</c:forEach>

现在我想合并两者,并且在 test.id 等于 test1.id 的地方,然后我想添加一个 html class="active"

我尝试了以下方法

<ul style="max-width: 300px;" class="nav nav-pills nav-stacked"  id="menuId">
<c:forEach items="${parentList}" var="test">
<c:forEach items="${savedParents}" var="test1">
<c:when test3="${test.id}==${test1.id }">
  <li ><a href="#" class="active" value="${test.id}-${test.category}" id="${parent.id}" onclick="return getQuestions(this);" >
  <input type="checkbox" value="${test.id}">${test.name }</a></li>

</c:when>
<c:otherwise>
  <li ><a href="#" value="${test.id}-${test.category}" id="${parent.id}" onclick="return getQuestions(this);" >
  <input type="checkbox" value="${test.id}">${test.name }</a></li>
</c:otherwise>

</c:forEach>

  <%-- <li ><a href="#" value="${test.id}-${test.category}" id="${parent.id}" onclick="return getQuestions(this);" >
  <input type="checkbox" value="${test.id}">${test.name }</a></li> --%>


</c:forEach>
 </ul>
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

但我在 eclipse 中遇到错误

Multiple annotations found at this line:
    - Missing required attribute 
     "test"
    - Undefined attribute name 
     "test3"
    - Missing required attribute 
     "test"
    - Undefined attribute name 
     "test3"

有人可以帮助我吗?

最佳答案

尝试以这种方式比较字符串

<c:when test="${test.id == test1.id }">

您还可以使用eq代替==

<c:when test="${test.id eq test1.id }">

关于spring - 如何使用 jSTL 比较 2 个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23947427/

相关文章:

java - spring-oxm:我可以解码文件的子元素吗?

java - JSP/JSTL 使用或不使用 <c :out> tags

java - 如何在 JSP 页面中打印错误堆栈跟踪?

jsf - 当 JSF 2 的 View 中存在元数据转换器时,为什么 JSTL-JSF2 无法正常工作

java - Vaadin + Spring Boot 中的自定义 servlet

java - Jacoco 插件不报告重命名的集成测试类的覆盖率

java - 标签liferay-ui :include is missing on liferay 6. 2

java - 如何在运行时加载的 jsp 中包含 html 片段?

java - jsp缓存标签库

java - Spring 安全与我自己的 table