@Test
public void testBean() throws Exception{
User user1=new User();
User user2=new User();
user2.setUsername("sssssssdsadss");
user2.setUserId(223);
user2.setPassword("dsds");
BeanUtils.copyProperties(user1, user2);
System.out.println(user1);
}
public class User {
private int userId;
private String username;
private String password;
public int getUserId() {
return userId;
}
public User setUserId(int userId) {
this.userId = userId;
return this;
}
public String getUsername() {
return username;
}
public User setUsername(String username) {
this.username = username;
return this;
}
public String getPassword() {
return password;
}
public User setPassword(String password) {
this.password = password;
return this;
}
@Override
public String toString() {
return "User [userId=" + userId + ", username=" + username + ", password=" + password + "]";
}
}
jar包:commons-beanutils-1.8.3.jar、commons-logging-1.1.1.jar