【发布时间】:2020-08-24 05:11:40
【问题描述】:
我是 oatpp 的初学者,正在构建一个 crud 操作演示应用程序。我想在 dto 中仅发送这四个属性中的两个(id、name、email、salary)以更改电子邮件服务,在请求负载中如下所示:
{
"id":"1",
"email":"email1"
}
【问题讨论】:
我是 oatpp 的初学者,正在构建一个 crud 操作演示应用程序。我想在 dto 中仅发送这四个属性中的两个(id、name、email、salary)以更改电子邮件服务,在请求负载中如下所示:
{
"id":"1",
"email":"email1"
}
【问题讨论】:
您可以通过创建包含这两个字段的单独 DTO 然后分配值来做到这一点,
或返回oatpp::Fields<oatpp::Any>。
ENDPOINT("GET", "/", myEndpoint) {
oatpp::Fields<oatpp::Any> responseDto = {
{"id", oatpp::Int32(1)}, //<-- put your id here
{"email", oatpp::String("email1")} //<-- put your email here
};
return createDtoResponse(Status::CODE_200, responseDto);
}
结果:
{"id":1,"email":"email1"}
【讨论】: