1.Error
对于新手来说也许会遇到的问题

解决方案
配置mybatis-config.xml ---><mapper>
代码:
<mappers>
<mapper resource="src/main/resources/mapper/UserMapper.xml"/>
</mappers>

之后测试又报错,说是没有找到src/main/resources/mapper/UserMapper.xml。

我遇到的是俩个问题:
1.首先要配置pom.xml,如果有父子工程最好都配置上,一般正常情况下只配置父工程就可以了
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
2.对于新手来说可能会遗忘resources是maven默认配置文件,所以不需要在<mapper resource="src/main/resources/mapper/UserMapper.xml"/>配置完整的路径,只配置resources下面的路径就可以了,对于我自己的项目正确路径是mapper/UserMapper.xml。
解决问题

我的项目结构

2.Error
org.apache.ibatis.binding.BindingException: Type interface com.wanghwei.dao.IUserMapper is not known to the MapperRegistry.

问题原因

3.Error
org.apache.ibatis.binding.BindingException: Type interface com.wanghwei.dao.IUserMapper is not known to the MapperRegistry.这个错误的原因是<mapper>中 namespace的命名空间有误
4.Error
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'mapper/UserMapper.xml'. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.wanghwei.dao.IUserMapper.getUserList. please check mapper/UserMapper.xml and mapper/UserMapper.xml
这个是由<select>中的id 方法名重复使用,在错误信息中就可以看出来
浙公网安备 33010602011771号