报错信息如下:
Opening JDBC Connection
Created connection 1988644427.
Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@76884e4b]
==> Preparing: select emp_id as empId, emp_name as empName, emp_salary as empSalary from t_emp where emp_id=?
==> Parameters: 1(Integer)
<== Columns: empId, empName, empSalary
<== Row: 1, tom, 999.99
Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@76884e4b]
Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@76884e4b]
Returned connection 1988644427 to pool.
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'empName' from result set. Cause: java.sql.SQLDataException: Cannot determine value type from string 'tom'
### The error may exist in mappers/EmployeeMapper.xml
### The error may involve com.boyan.mapper.EmployeeMapper.selectEmpById
### The error occurred while handling results
### SQL: select emp_id as empId, emp_name as empName, emp_salary as empSalary from t_emp where emp_id=?
### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'empName' from result set. Cause: java.sql.SQLDataException: Cannot determine value type from string 'tom'
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
解决思路:通过查看控制台输出日志信息,已经查找到正确内容,因此无法将查找到的数据和相应类型对应,问题应该是出现在测试返回路径中的文件中,检查过程文件中定义均正确,但测试依然存在问题。问题报错又是无法对应值的类型,所以去检查 pojo 类,再经查询发现 “MyBatis 需要默认构造函数来实例化对象”。所以发现问题所在,添加无参数构造函数后,✅测试成功,问题解决。
问题定位:pojo.Employee03.java 缺少无参数构造函数(错误原因:⚠️ MyBatis 需要默认构造函数来实例化对象)