java.lang.NoSuchMethodException: cn.pb.bean.Category.()报错

时间:2023-03-09 20:45:53
java.lang.NoSuchMethodException: cn.pb.bean.Category.<init>()报错

代码如下:

package cn.pb.bean;

import java.util.ArrayList;
import java.util.List; /**
* 分类的实体类
*/
public class Category {
private Integer cid;
private String cname;
private Integer pid; //父分类下子分类的集合
private List<Category> list = new ArrayList<Category>(); public Integer getCid() {
return cid;
} public void setCid(Integer cid) {
this.cid = cid;
} public String getCname() {
return cname;
} public void setCname(String cname) {
this.cname = cname;
} public Integer getPid() {
return pid;
} public void setPid(Integer pid) {
this.pid = pid;
} public List<Category> getList() {
return list;
} public void setList(List<Category> list) {
this.list = list;
} public Category(Integer cid, String cname, Integer pid, List<Category> list) {
this.cid = cid;
this.cname = cname;
this.pid = pid;
this.list = list;
} @Override
public String toString() {
return "Category{" +
"cid=" + cid +
", cname='" + cname + '\'' +
", pid=" + pid +
", list=" + list +
'}';
}
} 最后发现是我在代码最后写了个有参构造,重载了构造函数,而Mybatis在load进一个bean类时,需要无参构造从而导致了该错误, 解决方法,给代码加上午参构造即可!
public Category() {
super();
}