我正在编写一个java服务,我正在为输出构建文档.但我的结构应该是:OutPut Doc是顶级文档.在里面,我想有另一个Doc说中级文档,在这个中级文档中,我希望有Key值.
但我的问题是如何将一个文档插入另一个文档.我看到IDataUtil有一个方法,它要求键作为字符串,值可以是对象.
我的代码是 IDataUtil.put(idcvalueDoc, "Body", FullValue.toString());
但是这个Body应该不是字符串它应该是文档.我想将一个Doc插入另一个.
请帮我

要完成您的目标,您需要执行以下操作:
以下是演示此内容的示例Java服务(请注意,为方便起见,在这里对添加到intermediateDoc的键值元组进行了硬编码):
public static final void exampleService(IData pipeline) throws ServiceException {
IDataCursor pipelineCursor = pipeline.getCursor();
try {
// create an intermediateDoc IData object
IData intermediateDoc = IDataFactory.create();
// create a cursor to use to add key value tuples to the intermediateDoc
IDataCursor intermediateCursor = intermediateDoc.getCursor();
// add key value tuples as required to the intermediateDoc
IDataUtil.put(intermediateCursor, "key1", "value1");
IDataUtil.put(intermediateCursor, "key2", "value2");
// ...
// destroy the intermediateCursor when done adding key value tuples
intermediateCursor.destroy();
// create an outputDoc IData object
IData outputDoc = IDataFactory.create();
// create a cursor to use to add key value tuples to the outputDoc
IDataCursor outputCursor = outputDoc.getCursor();
// add the intermediateDoc to the outputDoc
IDataUtil.put(outputCursor, "intermediateDoc", intermediateDoc);
// destroy the outputCursor when done adding key value tuples
outputCursor.destroy();
// add the outputDoc to the pipeline
IDataUtil.put(pipelineCursor, "outputDoc", outputDoc);
} finally {
// destroy the pipelineCursor
pipelineCursor.destroy();
}
}
Run Code Online (Sandbox Code Playgroud)