当前位置:网站首页>A test class understands beanutils.copyproperties
A test class understands beanutils.copyproperties
2022-07-27 03:08:00 【Change with affection】
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.BeanUtils;
import java.math.BigDecimal;
public class Test2 {
public static void main(String[] args) {
UserDto userDto = new UserDto();
//BeanUtils.copyProperties(a,b) Yes, it will a Copy of data to b
User user = new User();
Salary salary = new Salary();
//a China and b The same attribute in will be replaced ( Different needs manual set), Copy class is b Whether it's worth it or not ;
BeanUtils.copyProperties(userDto, user);
//b Properties that exist in ,a There is no default in null
System.out.println(user + "--" + user.getDefaultClass().getInnerNum());
//User(id=2, name=2, sex=2, [email protected], innerClass=User.InnerClass(innerNum=4))--2
BeanUtils.copyProperties(userDto, salary);
System.out.println(salary);
//Salary(id=2, salary=null, idCard=null)
}
}
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
class DefaultClass {
Integer innerNum = 4;
}
@ToString
@Setter//Spring Of BeanUtils Of CopyProperties Method replication classes need setter Method ;
@Getter
class User {
private Integer id = 4;
private String name = "4";
private String sex = "4";
private DefaultClass defaultClass = new DefaultClass(4);
private InnerClass innerClass = new InnerClass();
// private User.InnerClass innerClass2 = new User.InnerClass(); Inner classes with exactly the same properties , But not the same inner class, that is, not the same object , Will not copy
@Data
class InnerClass {
Integer innerNum = 4;
}
}
@Data
class Salary {
private Integer id;
private BigDecimal salary;
private String idCard;
}
@Getter
//Spring Of BeanUtils Of CopyProperties The class whose method is copied needs getter Method ;
class UserDto {
private Integer id = 2;
private String name = "2";
private String sex = "2";
private DefaultClass defaultClass = new DefaultClass(2);
private InnerClass innerClass = new InnerClass();
// private UserSalaryDto.InnerClass innerClass2 = new UserSalaryDto.InnerClass();
class InnerClass {
Integer innerNum = 2;
}
}
边栏推荐
- {“errcode“:44001,“errmsg“:“empty media data, hint: [1655962096234893527769663], from ip: 222.72.xxx.
- 用最原始的方法纯手工实现常见的 20 个数组方法
- 商城小程序项目完整源码(微信小程序)
- Marqueeview realizes sliding display effect
- iNFTnews | GGAC联合中国航天ASES 独家出品《中国2065典藏版》
- B-树的应用以及添加和删除操作
- [二分查找简单题] LeetCode 35. 搜索插入位置,69. x 的平方根,367. 有效的完全平方数,441. 排列硬币
- 全网最全的软件测试基础知识整理(新手入门必学)
- OD-Paper【3】:Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
- [Ryu] common problems and solutions in installing Ryu
猜你喜欢

阿里云技术专家杨泽强:弹性计算云上可观测能力的构建

5、 MFC view windows and documents

从ACL 2022 Onsite经历看NLP热点

Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round

仿知乎论坛社区社交微信小程序

Static keyword

使用 WebSocket 实现一个网页版的聊天室(摸鱼更隐蔽)

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community

Ten thousand words long text, take you to understand the kubernetes network model

Interview shock 68: why does TCP need three handshakes?
随机推荐
论构造函数的原型是谁
[nisactf 2022] upper
Zhang Ping, Alibaba cloud Solution Architect: system construction of cloud native digital safety production
软件测试相关试题知识点
day6
LabVIEW中编程更改进程的优先级
商城小程序项目完整源码(微信小程序)
我的爬虫笔记(七) 通过爬虫实现blog访问量+1
Go to export excel form
Goatgui invites you to attend a machine learning seminar
[动态规划简单题] LeetCode 53. 最大子数组和
Kubernetes Dashboard 部署应用以及访问
Database read-write separation and database and table segmentation
Inftnews | "traffic + experience" white lining e Digital Fashion Festival leads the new changes of digital fashion
Pyqt5 use pyqtgraph to draw dynamic scatter chart
对象创建的流程分析
Cuteone: a onedrive multi network disk mounting program / with member / synchronization and other functions
Use the most primitive method to manually implement the common 20 array methods
Comprehensive summary of shell analysis log file commands
The most complete basic knowledge of software testing in the whole network (a must for beginners)