Can we perform reverse look up in Spring with EL Expressions

时间:2015-12-10 02:05:09

标签: spring

Can we perform reverse look up in Spring with EL Expressions: I have a util map in Spring with key - value pairs. I want to find they key by value using spring el expression... is that possible...

1 个答案:

答案 0 :(得分:0)

是的,您可以迭代地图并检查值是否等于您要查找的数据。如果是,请返回密钥。

//Java
Map<String, String> countryCapitalList = new HashMap<String, String>();
countryCapitalList.put("United States", "Washington DC");
countryCapitalList.put("India", "Delhi");
countryCapitalList.put("Germany", "Berlin");
countryCapitalList.put("France", "Paris");
countryCapitalList.put("Italy", "Rome");

request.setAttribute("capitalList", countryCapitalList);

// JSP

<c:forEach var="country" items="${capitalList}">
    <c:choose>
    <c:when test=${country.key == 'India'}
    Country: ${country.key}  - Capital: ${country.value}
    </c:when>
    </c:choose>
</c:forEach>

您可以在这里使用