学无先后,达者为师

网站首页 编程语言 正文

Invalid bound statement (not found): 各种原因

作者:一颗小小的石头. 更新时间: 2023-12-10 编程语言

这个问题出现在用xml配置mybatis的mapper时:

各种可能原因有:

**1.你的mapper写在了java目录里面。*例如下图:这样会出现一个问题,即使你在properties里面配置了 mybatis.mapper-locations= classpath:com/lihaoyu/demo/dao/*.xml,也没有用,因为编译的时候这个xml文件并没有被自动拉到target里面,毕竟编译的是.java文件而不是xml嘛,所以这时候应该在pom文件里面加上:
项目目录结构

 </build>
        <resources>
            <resource>
                <directory>src/main/java</directory><!--所在的目录-->
                <includes><!--包括目录下的.properties,.xml文件都会扫描到-->
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

如果你把xml放到了resources文件下,那么就只需要配置mybatis.mapper-locations=classpath:*/mapper/*.xml 就可以了,因为构建的时候会把resources里的东西自动拉到classpath下,注意.classpath意思就是编译后target文件夹下的classes目录.

2.xml里面的namespace不对 或者id和mapper里面的方法名不一样,或者parameterType对应不上,都会出现这种问题。

在这里插入图片描述

原文链接:https://blog.csdn.net/qq_37186947/article/details/88601304

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新