0

从 1.4.0 版本开始,“PropertyChange 现在与 Property 分离,从 propertyChange 到具体属性的引用被替换为 propertyName String 字段。”

1.4.0 更改后访问属性的替代方法是什么?因为我想在属性中访问“looksLikeId”

4

1 回答 1

2

您可以使用以下代码段执行此操作:

ManagedType managedType = (ManagedType)javers.getTypeMapping(Person.class);
Property property = managedType.getProperty(propertyChange.getPropertyName());

完整示例(常规):

def "should extract Property from PropertyChange"(){
  given:
  def javers = JaversTestBuilder.newInstance()

  when:
  def diff = javers.compare(new Person('1','bob'), new Person('1','bobby'))
  PropertyChange propertyChange = diff.changes[0]

  ManagedType managedType = (ManagedType)javers.getTypeMapping(Person)
  Property property = managedType.getProperty(propertyChange.propertyName)

  then:
  property.name == 'name'
  !property.looksLikeId()
}

在 1.4.1 版本中,我会getProperty()为 javers 添加便捷方法:

Property property = javers.getProperty( propertyChange )
于 2015-12-28T18:53:48.997 回答