Beanutils provides a wrapper for the Java launch and introspection API, and here's a small introduction to beanutils.copyproperties usage.
The function name lets you know that the Copyproperties function is a copy of the property, which has two parameters, one is the original data, and the other is the data that receives the attributes. Here is a hole I encountered: In different jar packages, the function of the two parameters of the position is not the same, there is a copyproperties (java.lang.Object dest, java.lang.Object source); The other is the opposite, copyproperties (Java.lang.Object source, Java.lang.Object dest), so you need to pay attention to the position of the parameter when you actually use it.
When the properties of the two objects are exactly the same, there is no doubt that the call to Copyproperties is completely successful, but what happens if there are different properties between the two objects, Beanutils does not handle the properties and requires manual processing by the programmer.
In addition to the beanutils, there is a tool class called Propertyutils, which also provides the Copyproperties () method, which is similar to the method described earlier, The only difference is that the copyproperties () method inside the Propertyutils tool class provides type conversion functionality that allows you to convert several types within a supported data type. Because of the increased type conversion, the speed is slightly slower. The types of conversions supported by Propertyutils are as follows:
*Java.lang.BigDecimal*Java.lang.BigInteger*Booleanand Java.lang.Boolean*byteand Java.lang.Byte*Charand Java.lang.Character*Java.lang.Class*Doubleand java.lang.Double*floatand java.lang.Float*intand Java.lang.Integer*Longand Java.lang.Long* Shortand Java.lang.Short*java.lang.String*java.sql.Date*Java.sql.Time* Java.sql.Timestamp
It is important to note that Java.util.Date is not supported here and only supports java.sql.Date, so you need to be aware of this when doing data type conversions.
Beanutils.copyproperties is useful, but it takes longer than manual calls to get and set methods, which can be considered if there is not much time required.
This article is referenced from: https://www.cnblogs.com/HassanBlog/articles/3200239.html
Usage of beanutils.copyproperties in Java