【SpringBoot+MyBatis】项目的Invalid bound statement (not found)错误

一、注意:我的mapper.xml在静态资源resources文件夹下

二、报错原因:

1、没有在 MyBatis 配置文件中正确配置  Mapper.xml 文件的位置或者配置了错误的位置 (本人出现的问题)

解决方案:在application.yml中添加 mapper-locations。

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

这段代码是 MyBatis 的配置文件中的一个标签,用于指定 Mapper XML 文件的位置。其中,mapper-locations 是属性名,classpath:mapper/*.xml 是属性值。

这里的 classpath: 表示从类路径下开始查找,而 mapper/*.xml 则表示在类路径下的 mapper 目录中查找所有后缀为 .xml 的文件,并将其作为 Mapper XML 文件使用。通常情况下,Mapper XML 文件都会放在单独的目录中,以便进行管理和维护。

2、mapper.xml中的namespace和实际的mapper文件不一致

解决方案:右键 UserMapper ——》Copy Path/Prference ——》Copy Prference,即可复制namespace路径。

 3、mapper接口中的方法名和mapper.xml中的id标签不一致

解决方案:检查id标签与方法名是否一样。

 4、Mapper.xml没有构建进去

解决方案:在target目录下看看对应的Mapper.xml文件在不在,若不在,点击右边的maven,clean一下,再Run一下。

猜你喜欢

转载自blog.csdn.net/weixin_52060913/article/details/131078025