如何访问属性?
How to access Property?
从 1.4.0 版本开始,
"PropertyChange is now decoupled from Property, reference from propertyChange to concrete property is replaced with propertyName String field."
1.4.0 更改后访问 属性 的替代方法是什么?因为我想在 属性
中访问 "looksLikeId"
您可以使用以下代码片段完成此操作:
ManagedType managedType = (ManagedType)javers.getTypeMapping(Person.class);
Property property = managedType.getProperty(propertyChange.getPropertyName());
完整示例(groovy):
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 版本中,我将为 javers 添加方便的 getProperty()
方法:
Property property = javers.getProperty( propertyChange )
从 1.4.0 版本开始, "PropertyChange is now decoupled from Property, reference from propertyChange to concrete property is replaced with propertyName String field."
1.4.0 更改后访问 属性 的替代方法是什么?因为我想在 属性
中访问 "looksLikeId"您可以使用以下代码片段完成此操作:
ManagedType managedType = (ManagedType)javers.getTypeMapping(Person.class);
Property property = managedType.getProperty(propertyChange.getPropertyName());
完整示例(groovy):
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 版本中,我将为 javers 添加方便的 getProperty()
方法:
Property property = javers.getProperty( propertyChange )