天天看点

【Mybatis报错】Invalid bound statement (not found)

今天启动项目的时候,spring boot报错了。

这个报错,是因为mapper文件没有被扫描到。

为什么没有扫描到呢?

原因分析

  1. namespace不正确
  2. 方法未定义 :Mapper.xml中的方法没有在java类中定义
  3. 返回值有误 :java类中的方法返回值,和xml文件中的返回值不同(ResultMap或者ResultType)
  4. 配置路径有误 :mapper文件的配置路径是否正确
    【Mybatis报错】Invalid bound statement (not found)
    【Mybatis报错】Invalid bound statement (not found)
    【Mybatis报错】Invalid bound statement (not found)

我的项目的报错原因是第4个:mapper文件的配置路径不正确

我在项目里配置的路径是:mapper文件夹下,及其子文件夹下的 所有xml文件。

但是,我的项目根本没有mapper文件夹。

【Mybatis报错】Invalid bound statement (not found)

光看这个文件夹,我并不知道它是一级目录,还是分级目录。

我当时新建文件夹的时候,是一口气输入的

虽然文件夹的名字写对了,但是这个文件夹的名字却是 mapper.subnet

【Mybatis报错】Invalid bound statement (not found)

在这样的情况,根本没有mapper文件夹,自然也就无法匹配了。