|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
javax.xml.bind.annotation Annotation Type XmlList
@Target(value={FIELD, METHOD, PARAMETER})
用来将属性映射到列表简单类型。
用法
@XmlList 注释能够与以下程序元素一起使用:
- JavaBean 属性
- 字段
在集合属性仅使用 @XmlElement 进行注释时,将通过元素包装集合中的每一个项。例如,
@XmlRootElement
class Foo {
@XmlElement
List<String> data;
}
将生成如下 XML:
另一方面,@XmlList 注释允许将多个值表示为单个元素中以空格分隔的标记。例如,<foo> <data>abc</data> <data>def</data> </foo>
@XmlRootElement
class Foo {
@XmlElement
@XmlList
List<String> data;
}
上述代码将生成如下 XML:
<foo> <data>abc def</data> </foo>
此注释可与以下注释一起使用:XmlElement、XmlAttribute、XmlValue 和 XmlIDREF。
- 使用 @XmlList 和
XmlValue(在允许的情况下)是多余的,因为XmlList将集合类型映射到一个简单模式类型,该简单模式类型就像XmlValue那样是由列表派生的。 - 使用 @XmlList 和
XmlAttribute(在允许的情况下)是多余的,因为XmlList将集合类型映射到一个简单模式类型,该简单模式类型就像XmlAttribute那样是由列表派生的。
| since | JAXB2.0 |
Used to map a property to a list simple type.
Usage
The @XmlList annotation can be used with the following program elements:
- JavaBean property
- field
When a collection property is annotated just with @XmlElement, each item in the collection will be wrapped by an element. For example,
@XmlRootElement
class Foo {
@XmlElement
List<String> data;
}
would produce XML like this:
@XmlList annotation, on the other hand, allows multiple values to be represented as whitespace-separated tokens in a single element. For example,<foo> <data>abc</data> <data>def</data> </foo>
@XmlRootElement
class Foo {
@XmlElement
@XmlList
List<String> data;
}
the above code will produce XML like this:
<foo> <data>abc def</data> </foo>
This annotation can be used with the following annotations:
XmlElement,
XmlAttribute,
XmlValue,
XmlIDREF.
- The use of @XmlList with
XmlValuewhile allowed, is redundant sinceXmlListmaps a collection type to a simple schema type that derives by list just asXmlValuewould. - The use of @XmlList with
XmlAttributewhile allowed, is redundant sinceXmlListmaps a collection type to a simple schema type that derives by list just asXmlAttributewould.
- Since:
- JAXB2.0
- Author:
- Kohsuke Kawaguchi, Sun Microsystems, Inc.
- Sekhar Vajjhala, Sun Microsystems, Inc.
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!