我在 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/