JAXB - Annotations, Class Fields as Attributes: XmlAttribute
Provided that XML lets you represent a data item as a single value, there is no cut-and-dried rule for deciding between using an element or an attribute. (If you look for guidance, the schema describing the XML Schema language itself, making judicious use of both, is a good example.) JAXB, of course, has to be told when to make a field into an XML attribute.
The annotation for creating an XML attribute is XmlAttribute. Its elements correspond to what can be defined in an XML schema:
namedefines the namestring for the attribute, the default being the class field's name.namespacespecifies the XML target namespace to be used for the attribute's name.- A "true" value of
requiredis the same as using the XML Schema definition's attributeuse="required".
If you ask about some way for defining the equivalent for the XML Schema attribute default="value", then the simple answer is: "Do it yourself." Just write the getter so that it returns the default value if the field's value is null.
It's possible to annotate a static final field with XmlAttribute. This has the same effect as an XML Schema definition where the attribute element's attribute fixed is set to that value.
@XmlAttribute
final static int answer = 42;
JAXB - Annotations, Class Fields as Attributes: XmlAttribute的更多相关文章
- JAXB - Annotations, Controlling Element Selection: XmlAccessorType, XmlTransient
If JAXB binds a class to XML, then, by default, all public members will be bound, i.e., public gette ...
- JAXB - Annotations, The Annotation XmlElement
The basic annotation for a field that's intended to be an element is XmlElement. It permits you to d ...
- JAXB - Annotations, Annotation for Classes: XmlType
This annotation adds information that would be available from a schema type, but isn't implied by a ...
- JAXB - Annotations, The Object Factory: XmlRegistry, XmlElementDecl
To be able to create objects from XML elements, the unmarshaller must have an object factory with me ...
- JAXB - Annotations, Type Adapters: XmlJavaTypeAdapter
For some Java container types JAXB has no built-in mapping to an XML structure. Also, you may want t ...
- JAXB - Annotations, Top-level Elements: XmlRootElement
A class that describes an XML element that is to be a top-level element, i.e., one that can function ...
- JAXB - Annotations, Annotations for the Schema: XmlSchema
This annotation can only be used with a package. It defines parameters that are derived from the xsd ...
- JAXB - Annotations, Type Mapping: XmlSchemaType
The annotation XmlSchemaType defines a mapping between an arbitrary Java type and a simple schema bu ...
- JAXB - Annotations, Annotations for Enums: XmlEnum, XmlEnumValue
An enum type is annotated with XmlEnum. It has an optional element value of type java.lang.Class whi ...
随机推荐
- Serach
1.二分查找 public class BubbleSort { public static int binarySerach(int[] a,int value){ int low=0; int h ...
- SQL 索引
1.http://www.cnblogs.com/AK2012/archive/2013/01/04/2844283.html 2 .聚簇索引和非聚簇索引的区别 3.聚集索引:只能有一个 (相当于字 ...
- After Android Studio update: Gradle DSL method not found: 'runProguard()'
1 具体报错为: Error:(16, 0) Gradle DSL method not found: 'runProguard()' Possible causes:<ul><li ...
- 关于AS3里的Matrix3D中的appendXXX和prependXXX
最近在看3D相关的一些基础,因为搞as3这么多年了,决定3D基础这块还是从AS3入手,3D游戏开发这块从U3D入手,扯远了,研究Matrix3D类时发现了矩阵处理转换时的一些方法均分为appendXX ...
- ECshop数据库的访问统计和管理员日志的清空
ECshop是个不错的系统,但是它有一定漏洞,若是访问量巨大的话,大量的访问统计代码会存入数据库的ecs_stats表中,甚至几天就可以达到几百兆,严重的网站直接就崩溃了.数据备份的时候也有很多不便, ...
- SpringMVC 参考文档
原文地址:http://blog.csdn.net/lufeng20/article/details/7598801
- 【转】Android studio 导入github工程
http://blog.csdn.net/feixiaku/article/details/45155587/ 从github下载两个开源项目: PagerSlidingTabStrip | ...
- 设置UITabBarController的背景颜色
if (IOS7) { self.tabBarController.tabBar.barTintColor = kTAB_BAR_GB_COLOR; }else{ self.tabBarControl ...
- [React Fundamentals] Using Refs to Access Components
When you are using React components you need to be able to access specific references to individual ...
- C 高级编程5 IO与文件权限
三.基于文件的描术符号 .得到文件描术符号/释入文件描术符号 a.文件类型 目录文件 d 普通文件 f 字符设务文件 c 块设备文件 b 软连接文件 l 管道文件 p socket文件 s 字符设备文 ...