今天在弄mybatis的时候,出现下面这个错误:
Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: No constructor found in com.contentsales.meta.User matching [java.lang.Integer, java.lang.String, java.lang.String, java.lang.Integer]
我的User类代码如下:
public class User {
private int id;
private String name;
private String password;
private int type;
public User(int id,String name,String password,int type){
this.id=id;
this.name=name;
this.password=password;
this.type=type;
}
看报错信息是说没有找到符合的构造函数,它需要[java.lang.Integer, java.lang.String, java.lang.String, java.lang.Integer]
,也就是说原始类型int
和对象类型Integer
是需要区分的,使用下面两种方案就可以解决:
1. 将这个构造函数的int
原始类型改成Integer
,即改成public User(Integer id,String name,String password,Integer type)
2. 不改的话,就在代码中再加上一个默认的构造函数,即添加
public User(){
}
原因还有待探究。。。