Java Reference
In-Depth Information
buffer.append("@");
buffer.append(entry.getValue());
}
return buffer.toString();
}
}
In Spring, a map is defined by the
<map>
tag, with multiple
<entry>
tags as children. Each entry
contains a key and a value. The key must be defined inside the
<key>
tag. There is no restriction on the
type of the key and value, so you are free to specify a
<value>
,
<ref>
,
<bean>
,
<idref>
, or
<null>
element
for them. Spring will also preserve the order of the map entries by using
java.util.LinkedHashMap
.
<bean id="sequenceGenerator"
class="com.apress.springenterpriserecipes.sequence.SequenceGenerator">
...
<property name="suffixes">
<map>
<entry>
<key>
<value>type</value>
</key>
<value>A</value>
</entry>
<entry>
<key>
<value>url</value>
</key>
<bean class="java.net.URL">
<constructor-arg value="http" />
<constructor-arg value="
www.apress.com"
/>
<constructor-arg value="/" />
</bean>
</entry>
</map>
</property>
</bean>
There are shortcuts to defining map keys and values as attributes of the
<entry>
tag. If they are
simple constant values, you can define them by
key
and
value
. If they are bean references, you can
define them by
key-ref
and
value-ref
.
<bean id="sequenceGenerator"
class="com.apress.springenterpriserecipes.sequence.SequenceGenerator">
...
<property name="suffixes">
<map>
<entry
key="type" value="A" />
<entry
key="url">
<bean class="java.net.URL">
<constructor-arg value="http" />
<constructor-arg value="
www.apress.com"
/>
<constructor-arg value="/" />
</bean>
Search WWH ::
Custom Search