我想知道如何使用String bean作为键从spring定义的Map中获取值。
我在xml中定义了以下地图:
Sub Tester()
Dim dontDelete As Variant
Dim sKeep As String, x As Long
Dim rngSearch As Range, c As Range
Dim i As Long, j As Long
dontDelete = Array("abel", "varo")
Dim deleteCell As Boolean
For x = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
Set c = Range("A" & x).Cells
deleteCell = True
For j = LBound(dontDelete) To UBound(dontDelete)
If InStr(c.Value, dontDelete(j)) Then
deleteCell = False
End If
Next j
If deleteCell Then c.Delete shift:=xlShiftUp
Next x
End Sub
我有以下简单的String bean:
<bean id="myMap" class="java.util.HashMap">
<constructor-arg>
<util:map>
<entry key="key1" value="Value1"/>
<entry key="key2" value="Value2"/>
</util:map>
</constructor-arg>
</bean>
要在我的xml中使用SPEL获取值,如下所示:
<bean id="mySimpleString" class="java.lang.String">
<constructor-arg value="key1"/>
</bean>
我的<bean class="com.my.MyClass">
<property name="someProp" value="#{myMap[#mySimpleString]}"/>
</bean>
值为空。
我做错了什么?
答案 0 :(得分:3)
由于myMap
是Map
,您应该使用#get()
方法来检索该值。
这会起作用
<property name="someProp" value="#{myMap.get(mySimpleString)}"/>