zoukankan      html  css  js  c++  java
  • 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);
    }
     
     
  • 相关阅读:
    idea项目maven配置
    IDEA配置maven项目启动
    IDEA导入本地项目教程
    EasyUi前端js禁止短时间内多次点击按钮方法
    EasyUi的form验证框位置修改
    div中的div如何居中
    Java导出Excel使用POI之SXSSFWorkbook方式
    java.lang.NoSuchMethodError
    eclipse导出项目时报错:problems were encountered during export
    直线检测方法—LSD论文翻译
  • 原文地址:https://www.cnblogs.com/z360519549/p/11540006.html
Copyright © 2011-2022 走看看