hutool-all 包把實體Bean轉化成字符串,以及把字符串轉化成Bean對象


GxyJobEntity gxyJobEntity1  = new GxyJobEntity();
        gxyJobEntity1.setUserId("user001");
        gxyJobEntity1.setPlanId("plan001");
        gxyJobEntity1.setStudentId("stu001");
        
        System.out.println(gxyJobEntity1);
        
        String str = JSONUtil.toJsonStr(gxyJobEntity1);
        System.out.println(str);
        
        GxyJobEntity studentEntity= JSONUtil.toBean(str,GxyJobEntity.class);
        System.out.println(studentEntity);
        
        System.out.println(gxyJobEntity1.equals(studentEntity));

輸出:

GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user001]
{"studentId":"stu001","planId":"plan001","userId":"user001"}
GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user001]
false

 

計算 當前時間 now 和 時間 date 之間間隔的天數: long daysUnSign = DateUtil.betweenDay(date, now, false) - 1;

把時間字符串轉化成Date:Date d = DateUtil.parseDate(bean.getESDATE());



二: List對象集合轉化成 String,以及把String 轉化成List 對象。
List<GxyEnterpriseDto> entityList 對象轉化成 string:
String str = JSONUtil.toJsonStr(entityList);

str 的值為:
[{"companyCode":"913303267429290899","date":1031241600000,"companyName":"浙江瑞聯電子科技有限公司","source":1},{"companyCode":"913305007272208214","date":986745600000,"companyName":"浙江潔美電子科技股份有限公司","source":1},{"companyCode":"91330400725261208A","date":973526400000,"companyName":"浙江永泰隆電子股份有限公司","source":1}]
再通過
List<GxyEnterpriseDto> enterpriseList = JSONUtil.toList(JSONUtil.parseArray(jsonstr),GxyEnterpriseDto.class); 轉化成 List 對象。


三: 把 String 轉化成
JSONArray :
String honorImg = dto.getHonorImg();
if(!StringUtils.isEmpty(honorImg)) {
JSONArray honorImgArray = JSONUtil.parseArray(honorImg);
}
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM