在写运行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部分) (注意大小写)