0

dto 对象:

public class DTOUser implements UserDetails {
/**
 * 
 */
private static final long serialVersionUID = -769714837633005963L;
private Long id;
private String account;
private String password;
private String statusStr;
private UserStatus status;
private int systemAdmin;
private long operator;
private String operateTime;
private String name;
private String company;
private String email;
private String telephone;
private List<DTOAuthority> dtoAuthorities = new ArrayList<DTOAuthority>();
private List<DTOAgreement> dtoAgreements = new ArrayList<DTOAgreement>();}

实体:

@Entity
@Table(name="adt_user")
public class User {
private long id;
private String account;
private String password;
private String statusStr;
private UserStatus status;
private int systemAdmin;
private long operator;
private String operateTime;
private String name;
private String company;
private String email;
private String telephone;
private Set<Authority> authorities = new HashSet<Authority>();
private Set<Agreement> agreements = new HashSet<Agreement>();}

我使用波纹管方法将值复制到实体,但有一个例外:

java.lang.IllegalArgumentException:无法调用 com.hna.adt.orm.User.setAuthorities - 参数类型不匹配

它出什么问题了 ?

BeanUtils.copyProperties(entity, value);
4

2 回答 2

1

如果您检查权限和协议的类型,它们与其他类定义不匹配。为了让 beanutils 正常工作,请确保属性类型匹配。

于 2013-09-28T07:15:02.913 回答
0

你有

private List<DTOAuthority> dtoAuthorities = new ArrayList<DTOAuthority>();

对比

private Set<Authority> authorities = new HashSet<Authority>();

如果BeanUtils.copyProperties只考虑元素的 setter 和 getter,并且不够聪明,无法弄清楚它们都是集合,并且一个一个地迭代和复制元素 - 这仍然需要Set兼容-那么它会抛出这个反射错误,然后不能从即不兼容分配。ListAuthorityDTOAuthoritySetList

如果您尝试在编译时做同样的事情

entity.setAuthorities(value.getDtoAuthorities());

然后你会得到与编译错误相同的 sessage。

您应该更改dtoAuthorities 为 aSet或更改authoritiesList.

于 2013-09-28T07:26:27.767 回答