我试图通过使用Spring Data MongoDB @LastModifiedDate
注释来引入审计。它适用于顶级文档,但我遇到了嵌入式对象的问题。
例如:
@Document(collection = "parent")
class ParentDocument {
@Id
String id;
@LastModifiedDate
DateTime updated;
List<ChildDocument> children;
}
@Document
class ChildDocument {
@Id
String id;
@LastModifiedDate
DateTime updated;
}
Run Code Online (Sandbox Code Playgroud)
默认情况下,当我parentDocument
使用内部children
列表保存实例时,updated
仅为列表中的parentDocument
任何对象设置值,而不为该对象设置值children
。但是在这种情况下,我也想对其进行审核。是否可以通过某种方式解决此问题?
我有这样的xml结构,我需要使用JAXB转换为java对象:
<elements>
<elemet>
<type></type>
<property1></property1>
<property2></property2>
<items>
<item>
<id></id>
<name></name>
</item>
...
<item>
<id></id>
<name></name>
</item>
</items>
</element>
</elements>
Run Code Online (Sandbox Code Playgroud)
我应该将此构造转换为具有嵌套项目列表的元素,而不是将每个项目转换为多个元素.这是Element类的示例:
class Element {
Integer type;
String property1;
String property2;
Integer itemId;
String itemName;
}
Run Code Online (Sandbox Code Playgroud)
我想在解组后得到它们的清单.对于所有列表元素,Type,property1和property2值应该相同.有没有可能使用JAXB解决这个问题?