arraylist—如何从pojo生成数组对象并在java中传入formparams

gc0ot86w  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(312)

我需要生成密钥作为 customerContactList[0].customerContactId 来自波乔。我已经尝试了arraylist,但我能够生成以下格式 customerContactList=[{ customerContactId=2 } ] 似乎对api请求无效。
此post api接受表单数据
如果我传入键值对 formParams.put("customerContactList[0].customerContactId", 2); 那么它就被认为是有效的。但我需要通过pojo生成相同的格式。

uelo1irk

uelo1irk1#

你的标准pojo应该是这样的。

{
  "customerContactList": [
    {
      "customerContactId": 2
    },
    {
      "customerContactId": 3
    }
  ]
}

也许这对你有帮助。

class Pojo {
    List<CustomerContact> customerContactList;
}

class CustomerContact {
    int customerContactId;
}

相关问题