java.lang.NoSuchMethodException_Error querying database. Cause: org.apache.ibatis.reflection.Reflec

java.lang.NoSuchMethodException_Error querying database. Cause: org.apache.ibatis.reflection.Reflec解决办法。

原因是没有提供空的构造方法

在实体类中提供了有参构造器,忽略了提供无参构造器,那么无参构造器就会被有参构造器覆盖。而恰巧mybatis需要调用该类的空构造器来完成实例化。所以会报下面的异常。

Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class net.neuedu.sm.domain.Users with invalid types () or values (). Cause: java.lang.NoSuchMethodException: net.neuedu.sm.domain.Users.()

The error may exist in file [D:\Users\Hero_mo\Documents\workspace-sts-3.9.9.RELEASE\mybatis_1026_sm_dao\build\classes\mapper\UserMapper.xml]

The error may involve user.queryUserById-Inline

The error occurred while setting parameters
SQL: select * from t_user where id=?

在这里插入图片描述
在这里插入图片描述

再去看了一眼我的实体类:
果然,少了一个空的构造方法

实体类提供了有参构造方法必须提供无参构造方法

package net.neuedu.sm.domain;

import java.io.Serializable;
import java.util.Date;

public class Users implements Serializable{
	private static final long serialVersionUID = 1918093918350712996L;
	private Integer id;
	private String username;
	private Date brithday;
	private String address;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public Date getBrithday() {
		return brithday;
	}
	public void setBrithday(Date brithday) {
		this.brithday = brithday;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	@Override
	public String toString() {
		return "Users [id=" + id + ", username=" + username + ", brithday=" + brithday + ", address=" + address + "]\n";
	}
	/**
	 * @param id
	 * @param username
	 * @param brithday
	 * @param address
	 */
	public Users(Integer id, String username, Date brithday, String address) {
		super();
		this.id = id;
		this.username = username;
		this.brithday = brithday;
		this.address = address;
	}	
}

你可能感兴趣的:(java.lang.NoSuchMethodException_Error querying database. Cause: org.apache.ibatis.reflection.Reflec)