mybatis报错invalid types () or values ()解决方法

版权声明:转载请注明出处。 https://blog.csdn.net/shuduti/article/details/53352425

Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.atguigu.mybatis_test.test1.User with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.atguigu.mybatis_test.test1.User.()

The error may exist in com/atguigu/mybatis_test/test1/userMapper.xml

The error may involve com.atguigu.mybatis_test.test1.userMapper.getUser-Inline

The error occurred while setting parameters

SQL: select * from user where id=?

Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.atguigu.mybatis_test.test1.User with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.atguigu.mybatis_test.test1.User.()

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
at com.atguigu.mybatis_test.test1.Test.main(Test.java:25)

Caused by: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.atguigu.mybatis_test.test1.User with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.atguigu.mybatis_test.test1.User.()
at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:86)
at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:48)
at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:41)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:528)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:507)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:331)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:291)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:266)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:236)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:150)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
… 3 more
Caused by: java.lang.NoSuchMethodException: com.atguigu.mybatis_test.test1.User.()
at java.lang.Class.getConstructor0(Class.java:2810)
at java.lang.Class.getDeclaredConstructor(Class.java:2053)
at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:60)
… 20 more

异常处理方式:

  • model中的get/set方法与成员变量不一。对相应的变量添加getter和setter方法。
  • 构造函数重载过后,没有添加无参的构造函数。添加无参的构造函数。
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页