【发布时间】:2021-10-27 13:50:21
【问题描述】:
我正在尝试从多个 DTO 创建一个大 DTO,但是将我的 DTO 放入列表中时遇到了很多麻烦。
我有两个 DTO:
class TypeDocDto : public oatpp::DTO
{
DTO_INIT(TypeDocDto, DTO)
DTO_FIELD(Int32, code);
DTO_FIELD(String, desciption);
};
class DocumentDto : public oatpp::DTO
{
DTO_INIT(DocumentDto, DTO)
DTO_FIELD(Int32, docNumber);
DTO_FIELD(Int32, typeDocNb);
DTO_FIELD(List<Object<TypeDocDto>>, typeDocs);
};
这里的想法是一个文档对象可以携带多个“TypeDoc”对象。
所以我尝试创建一个 TypeDocDto 列表,然后将其添加到我的 DocumentDto 对象中。
auto dtoDoc = DocumentDto::createShared();
dtoDoc->docNumber = 0; //That value is whatever for now.
dtoDoc->typeDocNb = 3;
oatpp::List<oatpp::Object<TypeDocDto>> typeDocsList = {};
for (int i = 0; i < dtoDoc->typeDocNb; i++)
{
auto typedocDto = TypeDocDto::createShared();
typedocDto->code = i;
typedocDto->desciption = "foo";
typeDocsList->emplace(typeDocsList->end(), typedocDto);
}
dtoDoc->typeDocs = typeDocsList;
但我无法在我的 typeDocsList 变量中添加任何内容。我添加的对象似乎总是 NULL。
我做错了什么?
【问题讨论】: