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);
}