[springBoot+Mybatis报错]解决:Invalid bound statement (not found): xxxxx

在写运行spring的时候总是出现

Invalid bound statement (not found): libaryapp.demo.dao.BooksDao.selectAll

这个问题始终无法解决 后面逐行去看配置文件 发现配置文件两个地方错误

  • application.propertis

修改前

mybatis.mapperLocations=classpath:mapper/*.xml

修改后

mybatis.mapperLocations=classpath*:libaryapp/demo/mapper/*.xml

一定要指定到xml的文件夹下面 而且记得classpath后面要加个* 不加也是会继续报这个错
一定要注意 放置的位置 我的是放在 dependencies下面的 build 中 plugins 下面

其次 注意 一定要注意!!! 不能有空格!!!!!
在这里插入图片描述
原代码

mybatis.mapperLocations=classpath* :libaryapp/demo/mapper/*.xml

修改后

mybatis.mapperLocations=classpath*:libaryapp/demo/mapper/*.xml

  • 检查 并在pom.xml中 加入
	<!-- 添加资源 -->

		<resources>

			<resource>

				<directory>src/main/resources</directory>

				<!-- src/main/resources下的指定资源放行 -->

				<includes>

					<include>**/*.properties</include>

					<include>**/*.yml</include>

					<include>**/*.xml</include>

				</includes>

				<filtering>false</filtering>

			</resource>

		</resources>

如果使用的是IDEA的话 请注意这个地方 (选择 Project Files 模式) 在resources中创建文件夹放xml文件。但是由于IDEA的创建机制 创建文件夹 不能像创建包名那样直接以com.newenergy.system这种形式直接创建(如果按这种形式创建说明只创建了一个文件夹名字叫com.newenergy.system 如图最下面框所显示)
只能一层一层的创建 如图中 中间红框所显示才是正确的层级关系
在这里插入图片描述


至于其他的方法
因为dao层是连接数据库相关的接口,所以dao层上一定要加注解 @Mapper 并且 里面的方法名 一定一定一定要跟xml中的 方法同名 (id部分) (注意大小写)

在这里插入图片描述
在这里插入图片描述

至此结束

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值