今天,我在自己写一个demo的时候出现了Invalid bound statement (not found)报错,我就开始在网上找错误原因。
1,你需要查看你的mapper.xml的namespace空间名称和mapper的地址是否一致
<mapper namespace="com.example.demo.dao.IUserMapper">
</mapper>
2,你需要查看你的方法名和.xml文件中的id值是否一致
<select id="selectByMySelf" resultType="com.example.demo.entity.User">
select * from mp_user
</select>
如果检查无误之后,还是同样的报错,那么还有以下两种解决方法:
1,在maven里的pom.xml文件中<build>标签下配置路径这样一段
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
2,在application.properties的文件中配置mapper文件的路径
mybatis-plus.mapper-locations= classpath:mybatis/mapper/*.xml
提示:我在检查了上述两项没有写错,然后添加了路径的配置之后,他还是报错。最后我发现是我在配置路径的时候多了一个空格,只是一个空格,然后他就找不到了。
由此证明,在写代码的时候细心是多么的重要,一个空格,困扰了我一个上午。