将地图键与某些元素进行比较,并根据结果显示其值 [英] Compare map keys with some element and based on the result show its values

查看:72
本文介绍了将地图键与某些元素进行比较,并根据结果显示其值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据条件从jsp中类型为Map <String, String>的映射中检索值.条件是将映射键与变量进行比较,如果键等于变量,则显示与该键有关的值.这是我在做什么:

I need to retrieve values from a map of type Map <String, String> in jsp based on a condition. The condition is to compare map key with variable and if the key equals the variable show the value pertaining to that key. Here's what I am doing:

<c:if test="${ myMap.key eq myVariable }">
<jsp:getvalueof var="testVariable" value = "${ myMap.value }" />
</c:if>

我期望得到的是,如果myMap.key等于myVariable,则应该在测试"变量中获取与该键有关的值.

What I am expecting to get is if the myMap.key equals myVariable, I should get the value pertaining to that key in "test" variable.

但是这个东西不起作用.请问有人知道吗?

But this thing is not working. Please any idea anyone?

先谢谢您了:)

推荐答案

您可以直接访问地图并将其值转换为"test"变量:

You can directly access the map and get the value into a 'test' variable:

<c:set var="test" value="${myMap[myVariable]}"/>

这篇关于将地图键与某些元素进行比较,并根据结果显示其值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆