【问题标题】:How to convert JavaBean contains List to Map in java如何在Java中将JavaBean包含List转换为Map
【发布时间】:2015-06-23 15:40:31
【问题描述】:
public class MyAgreementList {
    private String name;

    private List<MyAgreement> agreementList;

    public List<MyAgreement> getAgreementList() {
        return agreementList;
    }

    public void setAgreementList(List<MyAgreement> agreementList) {
        this.agreementList = agreementList;
    }


}

我想将 MyAgreementList 转换为 Map,有人可以帮助我吗? 我想要的结果是:Map有两个key:name,agreementList,List值不能丢

有什么框架可以支持吗?

【问题讨论】:

  • 结果如下:"agreementList" : [ { "productName" : null, "estiateRate" : null, "amount" : null, "arriveAmount" : null, "tips1" : null, " Tips2" : null, "agreementNumber" : null } ]

标签: java list dictionary


【解决方案1】:

psudocode:迭代列表并获取协议 id 并添加为密钥,否则为密钥维护一些计数器。希望这会有所帮助

for(MyAgreement mya : agreementList){
      map.put(mya.getId(),mya);
      //maintain a counter say counter
       //map.put(counter++,mya);
     }

【讨论】:

  • 我想要的结果是:Map有两个key:name,agreementList,List值不能丢失
猜你喜欢
  • 2019-11-20
  • 2018-07-28
  • 1970-01-01
  • 1970-01-01
  • 2021-02-23
  • 1970-01-01
  • 2017-07-14
  • 1970-01-01
  • 2013-07-22
相关资源
最近更新 更多