使用DBUtils反射数据到类的字段中抛出Cannot set xxx incompatible types, cannot convert java.lang.Integer to xx的解决方法
使用DBUtils反射数据库中的数据到自定义类的字段中抛出Cannot set xxx incompatible types, cannot convert java.lang.Integer to xxx
·
最近在学习javaweb,发现出现了一个bug:
我发现,在我的自定义类中的field和mysql中字段的类型不是一样的,所以导致反射失败抛出异常
又因为BeanListHandler中的反射是根据字段进行反射,从构造set方法中反射数据进字段,所以我修改了一下get和set方法
public UserBasic getAuthor_UseBasic() {
return author;
}
public void setAuthor(Integer author) {
UserBasic userBasic = new UserBasic();// UseBasic是我的自定义类
userBasic.setId(author);
this.author = userBasic;
}
更多推荐
所有评论(0)