簡體   English   中英

檢查地圖是否包含密鑰

[英]Checking if a map contains key

我嘗試在列表上設置值,如果地圖(我從spring控制器重定向)包含用戶ID的密鑰,則依賴於該列表。 我的代碼看起來像這樣:

<%@ page session="false"%>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="datatables" uri="http://github.com/dandelion/datatables"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

 <datatables:table id="users" url="${datasource}" serverParams="APP.datatables.helpers.extraParamsUsersList" serverSide="true" cssClass="appDataTable" autoWidth="false" stateSave="true" row="user" paginate="true" paginationType="full_numbers" info="false" filter="true" dom="plrtip" ext="columnFilterCallback" filterPlaceholder="none" displayLength="10">
     <!-- -->
     <c:set var="result" value="false"/>
     <c:forEach var="entry" items="${boxes}">                           
        <c:if test="${entry.key != user.id}">
            <c:set var="result" value="true"/>
        </c:if>
    </c:forEach>
    <c:if test="${result}">
        <!-- some code -->
    </c:if> 
</datatables:table>

地圖不為空並包含某些users鍵,但result始終為false。 我檢查了如果給出了用戶ID的真實值(例如1),那么我得到了正確的結果。 你知道我做錯了什么嗎?

<c:if test="${entry.key != user.id}">

你的意思是肯定的

<c:if test="${entry.key == user.id}">

但是你不需要迭代地圖。 只需使用containsKey()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM