Mybatis报错: Could not find resource mapper
一:.如果xml没有放在resources文件下,idea 的maven项目不会加载非resource目录下边的xml文件。1.可以把xml文件放在resources文件下2.或者在pom.xml文件下添加资源过滤<build><resources><resource><directory>src/main/java</directory>
·
一:.如果xml没有放在resources文件下,idea 的maven项目不会加载非resource目录下边的xml文件。
1.可以把xml文件放在resources文件下
2.或者在pom.xml文件下添加资源过滤
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
二 如果xml放在了resources文件下,还是报错
1.检查mybatis的配置文件是否出错
mybayis配置文件中绑定xml文件一共有三种方式
1.直接绑定xml文件 此种方式看看包名或者xml文件名称是否写错
包与包之间用/隔开
<mapper resource="com/kuang/dao/UserMapper.xml"/>
2.直接绑定class文件
<mappers>
<mapper resource="com/huahua/learn/dao/userMapper.xml" />
</mappers>
3.使用扫描包进行绑定
<mappers>
<mapper resource="com/huahua/learn/dao/userMapper.xml" />
</mappers>
第2种方式和第3种方式有前提条件:
接口和他的Mapper配置文件必须同名
接口和他的Mapper配置文件必须在同一级包下
2 3种方式 查看xml文件的路径是否与src路径下的接口路径一致
三: 如果排除 一 二种情况
检查xml文件中的resultType 是否写错
检查xml文件中的 resultType 是否有需要有用到自己写的实体类
如果 resultType 中写的是实体类的别名,查看是否在配置文件中配置实体类的别名
如果没有在配置文件中,配置实体类的别名,就必须在resultType 中写全实体类的路径
包名+类名
更多推荐
已为社区贡献3条内容
所有评论(0)