我正在寻找 BeanUtils.getProperty()
的替代品。我想要替代品的唯一原因是避免最终用户有更多的依赖性。
我正在处理自定义约束,这是我的一段代码
final Object firstObj = BeanUtils.getProperty(value, this.firstFieldName);
final Object secondObj = BeanUtils.getProperty(value, this.secondFieldName);
因为我需要从对象中获取这两个属性。
在没有任何第三方系统的情况下是否有任何替代方案,或者我需要从 BeanUtilsBean
复制这段代码?
最佳答案
如果您使用 SpringFramework,“BeanWrapperImpl”就是您正在寻找的答案:
BeanWrapperImpl wrapper = new BeanWrapperImpl(sourceObject);
Object attributeValue = wrapper.getPropertyValue("attribute");
关于java - 替代 BeanUtils.getProperty(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19402044/