Java:Spring框架:声明嵌套映射 [英] Java: Spring Framework: Declaring Nested Maps

查看:221
本文介绍了Java:Spring框架:声明嵌套映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在第4行收到错误说:
cvc-complex-type.2.4.d:从元素'map'开始发现无效内容。此时不会有子元素。

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> 

有什么建议吗?

推荐答案

对于复杂值类型,不要嵌套map元素,而是使用 value-ref 属性。默认情况下, value 元素只接受 String 值。

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


该属性可以是字符串,也可以使用JavaBeans PropertyEditor机制转换为所需类型。这使得应用程序开发人员可以编写可以将字符串转换为任意目标对象的自定义PropertyEditor实现。

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.

请注意,这仅适用于简单对象。通过使用对其他bean的引用填充JavaBean属性来配置更复杂的对象。

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

您的数据将类似于:

<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>

这篇关于Java:Spring框架:声明嵌套映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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