如何將linkedHashMap轉化為實體物件
阿新 • • 發佈:2019-02-05
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); } } }