简体   繁体   English

Java Accessor / Mutator->属性名称

[英]Java Accessor/Mutator -> Property name

What I am wondering, is there a libarary for Java that allows you to determine the name of a property given an accessor/mutator. 我想知道的是,有没有一个Java库,可以让您确定给定访问器/更改器的属性的名称。

Like so: 像这样:

getValue() -> value 
setAnotherValue(String v) -> anotherValue

I'm looking to use this property value with Apache BeanUtils to match the given setter/getter to the corresponding getter/setter respectively. 我正在寻找将此属性值与Apache BeanUtils配合使用,以将给定的setter / getter分别与相应的getter / setter进行匹配。

I know I've seen this behaviour before, but now that I am looking for it, I am unable to find a library that gives me this capabilty. 我知道我以前已经看到过这种行为,但是现在我正在寻找它,所以我找不到能够提供这种功能的图书馆。

Thanks. 谢谢。

java.beans.Introspector is useful for getting that information. java.beans.Introspector对于获取该信息很有用。 You want to use getBeanInfo() then from the bean info, you typically want to call getPropertyDescriptors() Using the property descriptor you can get the property names and then references to java.lang.reflect.Method objects for the appropriate getters and setters if you wish to invoke them. 您要使用getBeanInfo()然后通常要从bean信息中调用getPropertyDescriptors()使用属性描述符,可以获取属性名称,然后为适当的getter和setter引用java.lang.reflect.Method对象。您希望调用它们。

Good luck. 祝好运。

You can use describe to get the properties having corresponding accessor methods. 您可以使用describe获得具有相应访问器方法的属性。 To get for a specific accessor method, compare (using regex) from the returned set of properties. 要获取特定的访问器方法,请从返回的属性集中比较(使用正则表达式)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM