Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.selectAll Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.selectAll
Maven中Mybatis连接mysql报错:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.selectAll Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.selectAll
在看Mybatis教程的时候,Mybatis连接mysql报错,视频里没报错,没解决方法:
我搜了第一个报错,全是时区不一样,按着修改还是报错。后来发现是mybatis-config.xml没注册。
报错代码如下:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.selectAll Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.selectAll at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:135) at com.itheima.MyBatisDemo.main(MyBatisDemo.java:24) Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.selectAll at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:1009) at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:799) at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:792) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:146) ... 3 more
解决方法:Mappper没有注册,需要在mybatis-config.xml里面注册一下UserMapper.xml文件
<!-- UserMapper.xml为你要注册的xml文件 -->
<!-- 在mybatis-config.xml 添加-->
<mappers>
<mapper resource="UserMapper.xml"></mapper>
</mappers>
成功解决:
如果这没有解决的话,可以搜一下这个报错:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: Error querying database