Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有
@XmlAttribute(required=true)
在一个项目的数百个地方。
我可以将此设为默认值吗?...
...所以我只需要指定
@XmlAttribute(required=false)
需要的时候。
不,这种行为是根深蒂固的。但是,该required属性实际上是适当 XML 模式的轻量级替代方案。如果您需要更好地控制文档验证,那么我建议您为文档定义一个 XML 模式,并将该模式注入JAXBContext. 然后将在编组和解组时检查文档,您不必依赖注释进行验证。
required
JAXBContext