我遇到的情况是,我从 dto 获取一些字段并将它们插入到 xmlBean 中,例如:
xmlBeanItem.setProperty(dtoItem.getproperty());
问题在于,如果由于任何原因 dtoItem.getproperty() 返回 null,则 xmlBean 属性会生成一个空标记(例如 )。
有没有办法在不使用著名的 if 条件的情况下避免这种情况?到目前为止,我已经在表单上使用了它:
if (dtoItem.getJustification() != null) {
xmlBeanItem.setProperty(dtoItem.getproperty());
}
这会将圈复杂度增加到天文数字!!.
谢谢
最佳答案
不行,没有别的办法了。在 XmlSchema 中,空和缺席是两个不同的概念。这就是每个属性都有 xmlbean.isSetXXX() 和 xmlbean.isNilXXX() getter 的原因。
关于java - XML Beans 可选字段中的 Null 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9657578/