public class User {
private long id;
private String email;
private String password;
private String name;
public User() {
}
如果我去掉这个就会出错Exception in thread "main" org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.example.service.User]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.example.service.User.<init>()
薄荷糖与红茶
请问,在这节的代码里面,user这个class是加了一个不带参数的constructor的
如果我去掉这个就会出错Exception in thread "main" org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.example.service.User]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.example.service.User.<init>()
一路看下来应该是AbstractDao.getAll这里面BeanPropertyRowMapper.mapRow这里出的错。
我的问题是:
1.想了一下,感觉是应该为了把这个类的字段都提取出来需要实例化它一次(?),而且是对每一条记录?
2.作为一个准则就是应该给每个被Map的类都构建一个无参数的constructor吗?
谢谢