解决 Invalid bound statement (not found): XXXX 异常

解决Invalid bound statement not found 异常

异常环境

1、异常提示找不到 listQuery2方法

Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.huaw.mapper.excel.ExcelWorkBookMapper.listQuery2

2、MyBatis插件是正常的(不存在 select(ID)方法名不一致、namespace - mapper不一致问题)
插件是正常的,xml resultTypeparameterType都是正常
在这里插入图片描述
3、系统运行 spring-ioc容器代理是可以获取到 ExcelWorkBookMapper,但是就是找不到 listQuery2方法
在这里插入图片描述

解决

最后定位到 是 mapper-locations 配置问题

mybatis:
  mapper-locations: classpath:mapper/*.xml

红框选中的mapper.xml全都是异常,/excel/下的mapper文件无法被bind扫描,很奇怪

在这里插入图片描述
classpath:mapper/*.xml 这样的写法并没有递归所有文件目录

这样的写法 只能扫描到 resource/mapper/*.xml文件。是不能递归扫描到 resource/mapper/excel/*.xml

因为我一直用的都是 ibatis-plus, classpath:mapper/*.xml 这样的写法 在 MyBatis-PLUS 里面是可以的,这样是可以递归所有目录文件, 需要换一种写法:

mybatis:
  mapper-locations: classpath:mapper/**/*.xml

重新构建编译项目运行 一切正常了

MyBatis-PLUS 换回 MyBatis 发现 有些写法mybatis是不支持的,就拿我遇到的下面两个,plus是正常的,但是mybatis不行

  • xml sql语句 使用动态列名,使用 parameterType 返回 List或者当个对象,调用方法会发现返回的对象或者集合对象是空的,不会自动的把列字段名与对象字段名相互映射,需要使用 resultMap 指定映射关系。
  • classpath:mapper/*.xml 并不会递归扫描mapper下所有目录文件

建议还是少用MyBatis-PLUS 感觉太智能方便会让开发习惯都变得懒惰了,我也是觉得太方便了,才换回来的ibatis

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值