当前位置: 首页> 游戏> 攻略 > 网站制作公司收费情况_ppt汇报模板下载_百度一下官网手机版_快速建站平台

网站制作公司收费情况_ppt汇报模板下载_百度一下官网手机版_快速建站平台

时间:2025/7/14 15:18:10来源:https://blog.csdn.net/weixin_42933305/article/details/147093013 浏览次数:0次
网站制作公司收费情况_ppt汇报模板下载_百度一下官网手机版_快速建站平台

实体字段比较器(对比两组对象找出发生变化的字段工具类开发)

支持枚举映射
支持时间
支持显示对应字段中文描述
支持嵌套list等场景

下载地址
Java-对比两组对象找出发生变化的字段工具-支持枚举映射-支持时间-支持显示对应字段中文描述-嵌套list等场景-超越其他工具.rar

最新版本更新
https://code.jiangjiesheng.cn/article/366?from=csdn

package cn.jiangjiesheng.annoation.entitycomparator.demo;import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import cn.jiangjiesheng.service.impl.common.entitycomparator.demo.bizentity.SubTask;
import cn.jiangjiesheng.service.impl.common.entitycomparator.demo.bizentity.Task;
import cn.jiangjiesheng.service.impl.common.entitycomparator.demo.bizenum.Enum1Priority;
import cn.jiangjiesheng.service.impl.common.entitycomparator.demo.bizenum.Enum2Status;
import cn.jiangjiesheng.service.impl.common.entitycomparator.demo.bizenum.Enum3Type;
import cn.jiangjiesheng.service.impl.common.entitycomparator.impl.EntityComparator;import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;/*** 对比两组对象找出发生变化的字段工具类 测试验证*/
public class EntityComparatorDemo {public static void main(String[] args) throws Exception {String dateStr = "2025-03-04 12";DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH");// 解析字符串为LocalDateTime对象LocalDateTime localDateTime = LocalDateTime.parse(dateStr, formatter);// 如果需要转换为旧的Date类型Date date = java.sql.Timestamp.valueOf(localDateTime);SubTask oldSubTask = new SubTask("SubTaskOld", date, Enum2Status.PENDING, "2025-01-01");SubTask newSubTask = new SubTask("SubTaskNew", DateUtil.beginOfWeek(new Date()), Enum2Status.COMPLETED, "2025-01-02");List<SubTask> oldSubTasks = new ArrayList<>();oldSubTasks.add(oldSubTask);List<SubTask> newSubTasks = new ArrayList<>();newSubTasks.add(newSubTask);//再来一组,老的是空newSubTasks.add(newSubTask);Task oldTask = new Task(Enum1Priority.LOW, Enum2Status.PENDING, Enum3Type.TYPE_A.getCode(), oldSubTasks, oldSubTask, "2025-01-01");Task newTask = new Task(Enum1Priority.HIGH, Enum2Status.COMPLETED, Enum3Type.TYPE_B.getCode(), newSubTasks, newSubTask, "2025-01-02");List<EntityComparator.ChangeInfo> changes = EntityComparator.compareEntities(oldTask, newTask);// for (ChangeInfo change : changes) {//     System.out.println("Field: " + change.getFieldName());//     System.out.println("Description: " + change.getFieldDesc());//     System.out.println("Old Value: " + change.getOldValue());//     System.out.println("New Value: " + change.getNewValue());//     System.out.println();// }//这个保持了顺序,但是json结构混乱System.out.println("保持了顺序,但是json结构混乱:");System.out.println(EntityComparator.ChangeInfo.toOrderedJson(changes));System.out.println();// 这个未保持顺序,但是json结构清晰System.out.println("未保持顺序,但是json结构清晰:");System.err.println(JSONUtil.toJsonPrettyStr(changes));}
}

对比结果示例:

[ {"fieldDesc" : "任务优先级","fieldName" : "enum1Priority","newValue" : "高优先级","oldValue" : "低优先级"
},{"fieldDesc" : "任务状态","fieldName" : "enum2Status","newValue" : "已完成","oldValue" : "待处理"
},{"fieldDesc" : "任务类型","fieldName" : "taskType","newValue" : "类型B","oldValue" : "类型A"
},{"child" : [
[ {"fieldName" : "subTasks[0].name","fieldDesc" : "子任务名称","oldValue" : "","newValue" : "SubTaskNew"},{"fieldName" : "subTasks[0].dateTime","fieldDesc" : "时间日期类型","oldValue" : "","newValue" : "2025-04-07 00"},{"fieldName" : "subTasks[0].enum2Status","fieldDesc" : "子任务状态","oldValue" : "","newValue" : "已完成"},{"fieldName" : "subTasks[0].createdAt","fieldDesc" : "创建时间","oldValue" : "","newValue" : "2025-01-02"} ],
[ {"fieldName" : "subTasks[1].name","fieldDesc" : "子任务名称","oldValue" : "","newValue" : "SubTaskNew"},{"fieldName" : "subTasks[1].dateTime","fieldDesc" : "时间日期类型","oldValue" : "","newValue" : "2025-04-07 00"},{"fieldName" : "subTasks[1].enum2Status","fieldDesc" : "子任务状态","oldValue" : "","newValue" : "已完成"},{"fieldName" : "subTasks[1].createdAt","fieldDesc" : "创建时间","oldValue" : "","newValue" : "2025-01-02"} ],
[ {"fieldName" : "subTasks[2].name","fieldDesc" : "子任务名称","oldValue" : "","newValue" : "SubTaskNew"},{"fieldName" : "subTasks[2].dateTime","fieldDesc" : "时间日期类型","oldValue" : "","newValue" : "2025-04-07 00"},{"fieldName" : "subTasks[2].enum2Status","fieldDesc" : "子任务状态","oldValue" : "","newValue" : "已完成"},{"fieldName" : "subTasks[2].createdAt","fieldDesc" : "创建时间","oldValue" : "","newValue" : "2025-01-02"}]],"fieldDesc" : "子任务列表","fieldName" : "subTasks"
},{"fieldDesc" : "子任务名称","fieldName" : "subTask.name","newValue" : "SubTaskNew","oldValue" : "SubTaskOld"
},{"fieldDesc" : "时间日期类型","fieldName" : "subTask.dateTime","newValue" : "2025-04-07 00","oldValue" : "2025-03-04 12"
},{"fieldDesc" : "子任务状态","fieldName" : "subTask.enum2Status","newValue" : "已完成","oldValue" : "待处理"
},{"fieldDesc" : "创建时间","fieldName" : "subTask.createdAt","newValue" : "2025-01-02","oldValue" : "2025-01-01"
},{"fieldDesc" : "创建时间","fieldName" : "createdAt","newValue" : "2025-01-02","oldValue" : "2025-01-01"
} ]

最新版本更新
https://code.jiangjiesheng.cn/article/366?from=csdn

关键字:网站制作公司收费情况_ppt汇报模板下载_百度一下官网手机版_快速建站平台

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: