30s了解一个知识点之mybatis报错信息大全

1
映射文件没有配置namespace

org.apache.ibatis.binding.BindingException: Type interface com.sxt.interface_bind.mapper.UserMapper is not known to the MapperRegistry.

在这里插入图片描述
2
映射文件id不匹配

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.bupt.interface_bind.mapper.UserMapper.selById

在这里插入图片描述
3
索引越界异常
这个十分隐蔽,即使不调用其他的SQL语句,当其他语句#{}内为赋值就会报如下错误,原因是这里我们用的#{}作为占位符,底层其实是用
PreparedStatement发射器进行SQL语句的发送,那么该发射器会进行预编译,并且格式就不能改变了,因此会报该错误

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0

在这里插入图片描述
4

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.bupt.mapper.UserMapper.selAll

代码一定不满足
1 必要规范
1)namespace的值必须和对应接口的全限定路径一致;
2)SQL语句标签的id属性必须和当前绑定的接口中对用方法的名称一致;
2 可选规范
1)接口的名称和映射文件的名称一致;
2)将接口和映射文件放在相同的位置;.
其中一条
在这里插入图片描述
5
Resultmap集不包含student值,这个错误也比较隐蔽
因为是映射文件的问题并不属于4条必须要执行的规范
原因是当使用< ResultMap>标签时,主要是为了当数据库列名和POJO的属性名差很多相匹配时使用,当定义了resultMap时默认自动映射关闭,使用resultType时默认自动开启,因此当我使用了resultMap却并没有指定映射关系时,就会报结果集的sell()方法找不到,没有名为student的结果集当

org.apache.ibatis.builder.IncompleteElementException: Could not find result map 'com.bupt.mapper.StudentMapper.student' referenced from 'com.bupt.mapper.StudentMapper.selAll'

Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.bupt.mapper.StudentMapper.student

6
当我们将代码和配置文件分别放到src和resources时,此时我们可以通过< mapper resource>来扫描映射文件,但是此时注意是目录而不是包,需要用/来分割不能用点,或者可以使用package标签来扫描整个映射文件

 Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com.bupt.mapper.UserMapper.xml

Caused by: java.io.IOException: Could not find resource com.bupt.mapper.UserMapper.xml

在这里插入图片描述
7
结果集已经被定义,这个和端口号已经被占用挺像,就是同一个namespace下ResultSet不能重名

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/bupt/mapper/StudentMapper.xml'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.bupt.mapper.StudentMapper.stuMap

在这里插入图片描述
8
没有名为students属性的getter方法,我们知道NyBatis是通过反射拼接getter/setter方法来实现属性的赋值和查询的.故需要在POJO中生成getter/setter方法

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'students' in 'class com.bupt.pojo.Clazz'

此处属性写错成students,应该是list属性,而student只是其泛型
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吴成伟0122

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值