(Mybatis学习)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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值