1

嗨,我想显示这样的差异,我想知道 Javers 的最佳方法是什么:

a.name          leftV <-> rightB
a.b[0].value    leftV <-> rightB
a.b[0].c.foo    leftV <-> rightB

举个例子:

public class A {
    public A(String name, List<B> listOfB) {
        this.name = name;
        this.listOfB = listOfB;
    }

    String name;
    List<B> listOfB = new ArrayList<>();
}

public class B {
    public B(int id, String value, C c) {
        this.id = id;
        this.value = value;
        this.c = c;
    }

    @Id
    int id;
    String value;
    C c;
}

public class C {
    public C(String address) {
        this.address = address;
    }

    String address;
}

...
public void printGrpah() {
A a1 = new A("Foo", Arrays.asList(new B(1, "Bar", new C("Paris")), 
                                  new B(2, "Other", new C("Madrid"))));
A a2 =new A("Fooo", Arrays.asList(new B(1, "Bar2", new C("London"))));

我想得到类似的东西:

Updated:
    name                 Foo <-> Fooo
    listOfB[0].value     Bar <-> Bar2
    listOfB[0].c.address Paris <-> London

Added
    listOfB[1].value     Other
    listOfB[1].c.address Madrid

我不是在寻找最终的解决方案,而是更多的线索来看看我需要在哪里插入我的代码:

  • 我需要实现我自己的访问者吗
  • 加上自定义 ChangeProcessor
  • ...

提前谢谢。

克里斯托夫

4

1 回答 1

1

ChangeProcessor专为此类任务而设计。请参阅http://javers.org/javadoc_2.0/org/javers/core/Javers.html#processChangeList-java.util.List-org.javers.core.changelog.ChangeProcessor-

例如,要获取简单的更改日志,请调用:

 List<Change> changes = javers.calculateDiffs(...);
 String changeLog = javers.processChangeList(changes, new SimpleTextChangeLog());
 System.out.println( changeLog );
于 2016-09-12T13:25:58.327 回答