【问题标题】:sending request payload with oatpp使用 oatpp 发送请求负载
【发布时间】:2020-08-24 05:11:40
【问题描述】:

我是 oatpp 的初学者,正在构建一个 crud 操作演示应用程序。我想在 dto 中仅发送这四个属性中的两个(id、name、email、salary)以更改电子邮件服务,在请求负载中如下所示:

{
 "id":"1",
 "email":"email1"
}

【问题讨论】:

    标签: c++ oat++


    【解决方案1】:

    您可以通过创建包含这两个字段的单独 DTO 然后分配值来做到这一点, 或返回oatpp::Fields<oatpp::Any>

    使用 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"}
    

    【讨论】:

    • @Iganzzzo,我无法创建新的 DTO,因为我要求使用该 DTO,我已经这样做了,但被拒绝了。所以我只有一个选择。
    • @Iganzzzo,并希望返回与更新电子邮件的 id 相关的该 DTO 的所有数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    相关资源
    最近更新 更多