【Mybatis】解决Invalid bound statement (not found)


常见的可能情况有下列几个:


1.mapper.xml 里面的 namespace与实际类不一样

mapper.xml 里面的 namespace应该是其对应的接口路径。这个有个快捷的检测办法就是按住ctrl键,然后点击namespace里面的包名,如果能跳到对应的类,那就说明没问题。

<mapper namespace="...">

2.mapper接口的方法名称和mapper.xml里面的标签id不一致

这个问题也很常见,最好的办法还是复制过去,这样可以确保没得问题

Object xxx(Object obj);
<select id="xxx" resultMap="BaseResultMap">
    
</select>

3.构建没有进去,请看一下target文件夹下面这些是否存在,没有请重新构建

在这里插入图片描述
确认配置文件路径正确

# 配置mybatis
mybatis:
  mapper-locations: classpath:mapperxml/*.xml

可以下面内容添加进pom文件试试

<build>
	<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
	<resources>
	    <resource>
	        <directory>src/main/java</directory>
	        <includes>
	            <include>**/*.properties</include>
	            <include>**/*.xml</include>
	        </includes>
	        <filtering>false</filtering>
	    </resource>
	    <resource>
	        <directory>src/main/resources</directory>
	        <includes>
	            <include>**/*.properties</include>
	            <include>**/*.xml</include>
	        </includes>
	        <filtering>false</filtering>
	    </resource>
	</resources>
</build>

4. 如果使用mybatis-plus, 使用一下方法指定路径

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

版权声明:本文为happy488127311原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。