使用MyBatis框架中经常会看到这样的异常,今天跟着源码看一下这条异常的抛出路径:
先根据路径找到org.apache.ibatis.binding.BindingException这个异常类(Ctrl + Shift + R没有直接定位到该类,具体原因待分析),源代码如图1
Ctrl + H中也没定位到Parameter '__frch_item_0' not found. Available parameter,只能通过Ctrl + Shift + G一个个查看BindingException几个构造函数的调用位置了。
查找一遍后,确定该条异常只有在org.apache.ibatis.binding.MapperMethod中的内部静态类ParamMap<V>中抛出
可以看到MyBatis是将Mapper中的参数都封装成HashMap对象,该内部静态类是在MapperMethod中的convertArgsToSqlCommandParam方法中进行了调用,
上一级调用为同一个类下的execute(SqlSession sqlSession, Object[] args)方法,
再上一级是org.apache.ibatis.binding.MapperProxy中的invoke(Object proxy, Method method, Object[] args)方法,
再上一步org.apache.ibatis.binding.MapperProxyFactory.newInstance(SqlSession sqlSession),
再往上org.apache.ibatis.binding.MapperRegistry,
在Spring托管MyBatis的项目里,如何加载初始化MyBatis,进而调用到MapperRegistry
可以参考文章https://www.jianshu.com/p/970120e36acf