1

建立jb

JaversBuilder jb = JaversBuilder.javers().withMappingStyle(MappingStyle.BEAN).withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).withPrettyPrint(true)

接着

log.info(diff.prettyPrint())

1. ListChange{globalId:'fn.dsl.diff.javers.Instance/Folder:{0F1E2D3C-4B5A-6978-8796-A5B4C3D2E1F0}', property:'permissions', containerChanges:[(3).removed:'fn.dsl.diff.javers.Permission {type: 'ALLOW', mask: '135159', GN: 'entos_users_tst@tn.fntst.ru', GT: 'GROUP', source: 'DIRECT', depth: 'THIS_OBJECT_ONLY' }', (2).'fn.dsl.diff.javers.Permission {type: 'ALLOW', mask: '999415', GN: 'entos_admins_tst@tn.fntst.ru', GT: 'GROUP', source: 'DIRECT', depth: 'THIS_OBJECT_ONLY' }' to 'fn.dsl.diff.javers.Permission {type: 'ALLOW', mask: '135159', GN: 'entos_users_tst@tn.fntst.ru', GT: 'GROUP', source: 'DIRECT', depth: 'THIS_OBJECT_ONLY' }']}

,但期望漂亮的格式。就像在文档中一样 - http://javers.org/documentation/diff-examples/#compare-valueobjects

System.out.println(diff);

//.. shouldDetectBossChange()

Diff:
1. ReferenceChange{
   globalId:'org.javers.core.examples.model.Employee/Great Developer',
   property:'boss',
   oldRef:'org.javers.core.examples.model.Employee/Manager One',
   newRef:'org.javers.core.examples.model.Employee/Manager Second'}
2. ListChange{
   globalId:'org.javers.core.examples.model.Employee/Manager Second',
   property:'subordinates',
   containerChanges: [(0).added:'org.javers.core.examples.model.Employee/Great Developer']}
3. ListChange{
   globalId:'org.javers.core.examples.model.Employee/Manager One',
   property:'subordinates',
   containerChanges:[(0).removed:'org.javers.core.examples.model.Employee/Great Developer']}

我做错了什么?我应该期待文档中显示的漂亮格式还是手动格式化?

4

1 回答 1

4

在您所指的文档中,手动添加了换行符。

diff.toString()并且diff.prettyPrint()(因为它只是别名)在每次更改后添加 br 。因此,即使是带有一系列 ElementChanges 的 ListChange 也会打印在一行中。

使用ChangeProcessor 自定义您的差异格式。请参阅SimpleTextChangeLog示例

于 2016-06-23T05:47:40.933 回答