Java: Spring Framework: Declaring Nested Maps

血红的双手。 提交于 2019-12-04 12:33:52

问题


I get an error at 4th line saying: cvc-complex-type.2.4.d: Invalid content was found starting with element 'map'. No child element is expected at this point.

  <util:map id="entirePayTypesMap">
            <entry key="34">
                <value>
                    <map>
                         <entry key="default">
                              <value>
                                 <map  key-type="java.lang.Boolean">
                                     <entry key="true" value="3T" />
                                     <entry key="false" value="3U" />
                                 </map> 
                              </value>
                         </entry>
                     </map> 
                </value>
            </entry>
    </util:map> 

Any suggestions?


回答1:


For complex value types, do not nest the map element, instead use value-ref attributes. By default, value elements only accept String values.

The property may be a string, or may be converted to the required type using the JavaBeans PropertyEditor machinery. This makes it possible for application developers to write custom PropertyEditor implementations that can convert strings to arbitrary target objects.

Note that this is recommended for simple objects only. Configure more complex objects by populating JavaBean properties with references to other beans.

Your data will look something like:

<util:map id="mapA" key-type="java.lang.Boolean">
    <entry key="true" value="3T" />
    <entry key="false" value="3U" />
</util:map>
<util:map id="map1">
    <entry key="default" value-ref="mapA"/>
</util:map>

<util:map id="mapB" key-type="java.lang.Boolean">
    <entry key="true" value="4T" />
    <entry key="false" value="4U" />
</util:map>
<util:map id="map2">
    <entry key="default" value-ref="mapB"/>
</util:map>

<util:map id="entirePayTypesMap">
    <entry key="34" value-ref="map1"/>
    <entry key="35" value-ref="map2"/>
</util:map>



回答2:


<util:map id="map1" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.util.HashMap">

<entry key="" value-ref="map2">

</util:map>



<util:map id="map2" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.util.HashMap">

<entry key="" value-ref="map3">

</util:map>



<util:map id="map3" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.Boolean">

<entry key="" value="">

</util:map>


来源:https://stackoverflow.com/questions/963599/java-spring-framework-declaring-nested-maps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!