Spring: How can you declare name / value pairs outside of the map?
I need to set a set of name / value pairs inside my application - effectively representing a many-to-many map (ie keys can have multiple values ββand vice versa), so Hashtable and Hashmap don't really work for me.
I would like to declare them via Spring in a format similar <props>
, but of course this won't work directly because Properties extends the Hashtable itself.
IE, I want to be able to declare something like this:
<entry>
<key><value>KeyOne</value></key>
<value>ValueOne</value>
</entry>
<entry>
<key><value>KeyOne</value></key>
<value>ValueTwo</value>
</entry>
inside a property - but can't use <map>, <props>
and can't see a good way to use <set>
or <list>
. Any bright ideas?
I don't necessarily need the syntax above; but for now, since I originally implemented this code with HashMap, since the actual data structure is set by Spring. After finding my 1-1 card, it really is 1-many or even many-many, here I am.
Thank.
source to share
How do I set your records as simple strings and decode the key and value?
@Required
public void setData(String[] data) {
// split each data element into key and value at the comma
}
<property name="data">
<list>
<value>key,value</value>
<value>key,value</value>
</list>
</property>
This works more, but you end up with compact XML.
source to share