0

我处于从 dto 获取一些字段以将它们插入 xmlBean 的情况,例如:

xmlBeanItem.setProperty(dtoItem.getproperty());

问题在于,如果出于任何原因 dtoItem.getproperty() 返回 null,则 xmlBean 属性会生成一个空标记(例如 )。

有没有办法在不使用著名的 if 条件的情况下避免这种情况?到目前为止,我已经在表单上使用了它:

if (dtoItem.getJustification() != null) {
     xmlBeanItem.setProperty(dtoItem.getproperty());
}

这会将圈复杂度增加到天文数字!

谢谢

4

1 回答 1

1

不行,没有别的办法。在 XmlSchema 中,null 和缺席是两个不同的概念。这就是为什么每个属性都有 xmlbean.isSetXXX() 和 xmlbean.isNilXXX() getter。

于 2012-03-11T19:50:08.667 回答