mybatis查询操作出现异常
异常提示:
org.apache.ibatis.exceptions.PersistenceException:
- Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.dc.mybatis.User with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.dc.mybatis.User.<init>()
- The error may exist in mappers/UserMapper.xml
- The error may involve com.dc.mybatis.UserMapper.queryUserAll
- The error occurred while handling results
- SQL: select * from tb_user
- Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.dc.mybatis.User with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.dc.mybatis.User.<init>()
错误原因:在User类中添加了一个有参的构造方法后查询语句开始统一报这个错误,因为mybatis查询成功后会调用实体类中的无参构造方法新建实体对象然后返回。
解决方法:将无参的构造方法添加到实体类中即可解决