2 xyforall xyforall 于 2014.09.14 11:43 提问

我用BeanUtils时,怎么也拷贝不了,也没报任何错误,求助
@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

Csdn user default icon
上传中...
上传图片
插入图片