JavaBeans Comparison(JavaBeans 比较)
问题描述
Does anyone know about a free open source library (utility class) which allows you to compare two instances of one Java bean and return a list/array of properties which values are different in those two instances? Please post a small sample.
Cheers
Tomas
BeanComparator of Apache commons is what you are looking for.
Update. A simple example that compares JavaBeans with one property (comparation is made agains only one property, you should create as many BeanComparators as properties you want to match).
After some tests one result is successful. This is the output:
Obviously increasing TestBean array size will increase the chances to get matches.
You need to import to your project the following jars: commons-logging-version.jar, commons-beanutils-version.jar, commons-beanutils-core-version.jar, commons-beanutils-bean-collections-version.jar, commons-collections-version.jar.
The files are included inside commons-logging, commons-beanutils and commons-collections APIs.
这篇关于JavaBeans 比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!