首页 > 解决方案 > 即使它们相同,也将属性添加到更改列表中。(Javers)

问题描述

我有一个 POJO 如下

class Employee{

private int id;
private String name;
private String profession;
private int experince;

public Employee(int id, String name, String profession, int experience){
this.id = id;
this.name = name;
this.profession = profession;
this.experience = experience;
}

我有两个要比较的对象

Employee emp1 = new Employee(1, "John Doe", "Architect",10);
Employee emp2 = new Employee(2, "Michael", "Developer",10);

我比较两个对象并获得更改

Diff diff = javers.compare(emp1,emp2);
List<Change> changes = diff.getChanges();

有了这个,我得到(id,name,professional)作为改变的属性,它们各自的左值和右值。

有什么方法可以将“经验”也包含在左右值相同的更改中?

标签: javajavers

解决方案


简短的回答是否定的,更改视图报告,好吧,只是改变了一些事情。也许您需要快照视图或阴影视图?

  • 影子是从快照恢复的域对象的历史版本。
  • 变化代表两个对象之间的原子差异。
  • 快照是作为属性:值映射捕获的域对象的历史状态

https://javers.org/documentation/jql-examples/#data-history-views


推荐阅读