BeanUtils.copyProperties進行對象之間的屬性賦值

1:BeanUtils.copyProperties方法進行對象之間屬性的賦值,避免通過get、set方法一個一個屬性的賦值

public class BeanUtilsTest {
    public static void main(String[] args) {
        student student = new student("william","123");
        User user = new User();
        BeanUtils.copyProperties(student,user);
        System.out.println(user.toString());
    }
}
@Data
@AllArgsConstructor
class student{
    private String name;
    private String password;
}
@Data
class User{
    private String name;
    private String password;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章