Cause: java.lang.NoSuchMethodException: spring_cache.springtest.dao.Employee.<init>()?

图片说明

以下是pojo

 package spring_cache.springtest.pojo;

public class Employee {

    private Integer id;
    private String lastName;
    private String email;
    //性别 1男  0女
    private Integer gender;
    private Integer dId;

    public Employee() {
    }


    public Employee(Integer id, String lastName, String email, Integer gender, Integer dId) {
        super();
        this.id = id;
        this.lastName = lastName;
        this.email = email;
        this.gender = gender;
        this.dId = dId;
    }

    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public Integer getGender() {
        return gender;
    }
    public void setGender(Integer gender) {
        this.gender = gender;
    }
    public Integer getdId() {
        return dId;
    }
    public void setdId(Integer dId) {
        this.dId = dId;
    }
    @Override
    public String toString() {
        return "Employee [id=" + id + ", lastName=" + lastName + ", email=" + email + ", gender=" + gender + ", dId="
                + dId + "]";
    }



}

mapper文件

 package spring_cache.springtest.dao;

import org.apache.ibatis.annotations.*;

/**
 * @author Dell
 */
@Mapper
public interface Employee {
        @Select("SELECT * FROM employee WHERE id=#{id}")
        public  Employee getEmployeeById(Integer id);
        @Update("update Employee set lastName=#{lastName},email=#{email},gender=#{gender},d_id=#{dId} where id=#{id}")
        public Employee updateEmp(Employee emp);
        @Delete("delete from Employee where id=#{id}")
        public void deleteEmp(Employee emp);
        @Insert("insert into Employee(lastName,email,gender,d_id) values(#{lastName},#{email},#{gender},#{dId})")
        public void InsertEmp(Employee emp);
}

配置文件

 spring.datasource.url=jdbc:mysql://localhost:3306/spring_cache
spring.datasource.username=root
spring.datasource.password=123

测试类

package spring_cache.springtest;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import spring_cache.springtest.dao.Employee;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringtestApplicationTests {
    @Autowired
    Employee employee;
    @Test
    public void contextLoads() {
        Employee employeeById = employee.getEmployeeById(1);
        System.out.println(employeeById);
    }

}


错误信息

Caused by: org.apache.ibatis.reflection.ReflectionException: Error instantiating interface spring_cache.springtest.dao.Employee with invalid types () or values (). Cause: java.lang.NoSuchMethodException: spring_cache.springtest.dao.Employee.<init>()

0

1个回答

解决了,mapper文件以mapper后缀命名

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!