如何将linkedHashMap转化为实体对象

import lombok.Data;

import java.util.List;
@Data
public class ProfitPage<T> {

    private int pageSize ; //页码
    private int total; //总条数
    private Integer size;  //当前页
    private int pageNo;//页码
    private List<T> detail;

    public ProfitPage(int total){
        this.total = total;
    }

    /**
     * 获取总页数
     * @return
     */
    public int getTotalPages() {
        int totalPages = total / Constants.PROFIT_BATCH_NUM;
        if(total % pageSize != 0){
            totalPages++;
        }
        return totalPages;
    }

}
detail是ProfitPage对象;

ProfitPage对象是通过JsonString转换过来的

Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
String jsonString = gson.toJson(detail.getDetail());
List<VbillCardProfitBean> vbillQrcodeProfitBeans = gson.fromJson(jsonString,List.class);
在这里并没有将list集合转换为List<vbillQrcodeProfitBeans>,还需要将遍历一遍
if(vbillQrcodeProfitBeans!=null&&vbillQrcodeProfitBeans.size()>0){
    for (Object vbillCardProfitBeanLinked:
            vbillQrcodeProfitBeans ) {
        String vbillCardProfitBeanStr = gson.toJson(vbillCardProfitBeanLinked);
        VbillCardProfitBean vbillCardProfitBean = gson.fromJson(vbillCardProfitBeanStr,VbillCardProfitBean.class);
     
        }

    }
}

猜你喜欢

转载自blog.csdn.net/m0_37708405/article/details/82056733