Usage of beanutils.copyproperties in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.