Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of the assignment order of BeanUtils.copyProperties () Parameter

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the example analysis of the assignment order of BeanUtils.copyProperties () parameter". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "BeanUtils.copyProperties () parameter assignment order example analysis"!

Catalogue

The assignment order of the BeanUtils.copyProperties () parameter

The first experience of BeanUtils.copyProperties and the explanation of the meaning of its parameters

Use

Case: create a source class: source

Create a target target source class

Create a test class test

IgnoreProperties parameter

Case

Case testing

The assignment order of the BeanUtils.copyProperties () parameter

BeanUtils.copyProperties has two different jar packages, introducing different packages and assigning values in a different order.

They are:

Org.springframework.beans.BeanUtilsorg.apache.commons.beanutils.BeanUtils

If you introduce 1, you will assign x to y.

If you introduce 2, you assign y to x.

The first experience of BeanUtils.copyProperties and the use of explaining the meaning of its parameters

BeanUtils.copyProperties is a property assignment between objects under the org.springframework.beans.BeanUtils; package, which avoids the routine operation of get and then set attribute values one by one, and is very easy to use.

Case: create a source class: source private String username; private String password; private String email; public String getUsername () {return username;} public void setUsername (String username) {this.username = username;} public String getPassword () {return password;} public void setPassword (String password) {this.password = password;} public String getEmail () {return email } public void setEmail (String email) {this.email = email;} @ Override public String toString () {return "book {" + "username='" + username +'\'+ ", password='" + password +'\'+ ", email='" + email +'\'+'}' }} create a target target source class private String username; private String password; private String email; public String getUsername () {return username;} public void setUsername (String username) {this.username = username;} public String getPassword () {return password;} public void setPassword (String password) {this.password = password;} public String getEmail () {return email } public void setEmail (String email) {this.email = email;} @ Override public String toString () {return "book {" + "username='" + username +'\'+ ", password='" + password +'\'+ ", email='" + email +'\'+'}' }} create test class testimport com.sdqj.system_integration.domain.book;import com.sdqj.system_integration.domain.book2;import org.springframework.beans.BeanUtils;public class test {public static void main (String [] args) {book bo=new book (); bo.setEmail ("1111"); bo.setPassword ("1111"); bo.setUsername ("333"); book2 bo2=new book2 () BeanUtils.copyProperties (bo,bo2); System.out.println (bo.toString ()); System.out.println (bo2.toString ());}}

The results show:

IgnoreProperties parameter

IgnoreProperties parameter means to ignore a parameter so that it is not copied, and you can write multiple ignored parameters.

Case import com.sdqj.system_integration.domain.book;import com.sdqj.system_integration.domain.book2;import org.springframework.beans.BeanUtils;public class test {public static void main (String [] args) {book bo=new book (); bo.setEmail ("1111"); bo.setPassword ("1111"); bo.setUsername ("333"); book2 bo2=new book2 () BeanUtils.copyProperties (bo,bo2, username, password); System.out.println (bo.toString ()); System.out.println (bo2.toString ());}

The results show:

There is also the Class editable parameter in the source code, which I don't know much about, but I can only put target (target class).

Case test public static void main (String [] args) {book bo=new book (); bo.setEmail ("1111"); bo.setPassword ("222nd"); bo.setUsername ("333"); book2 bo2=new book2 (); BeanUtils.copyProperties (bo,bo2,book2.class); System.out.println (bo.toString ()); System.out.println (bo2.toString ());}

The results are as follows:

At this point, I believe you have a deeper understanding of the "instance analysis of the assignment order of BeanUtils.copyProperties () parameters", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report