有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我需要从Pojo生成customerContactList[0].customerContactId密钥。我尝试过使用arrayList,但我能够以下面的格式生成customerContactList=[{ customerContactId=2 } ],这对于API请求来说似乎是无效的

  • 此Post API接受表单数据
  • 如果我键入键值对{{CD3}},则认为它是有效的。但我需要通过Pojo生成相同的格式

共 (1) 个答案

  1. # 1 楼答案

    你的标准pojo应该是这样的

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

    也许这对你有帮助

    class Pojo {
        List<CustomerContact> customerContactList;
    }
    
    class CustomerContact {
        int customerContactId;
    }