1.xml配置运行时没被读取到
报错:
Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/CGL/Dao/UserDao.xml
解决方案:
maven中配置
<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>
maven由于他的约定大于配置,我们之后可能遇到我们写的配置文件,无法被导出或者生效
2.mapper.xml没在mybatis主配置中注册
报错:
org.apache.ibatis.binding.BindingException: Type interface com.CGL.Dao.UserDao is not known to the MapperRegistry.
解决方案:
在mybatis主配置文件中加上
<mappers>
<mapper resource="com/CGL/Dao/UserDao.xml"/>
</mappers>
3.UserMapper.xml数据错误
<mapper namespace="com.CGL.Dao.UserDao"> <!--namespace声明要操作的接口-->
<select id="getUserList" resultType="com.CGL.Pojo.User"> <!--id 对应接口中的方法名 resultType 返回类型-->
select * from mybatis.myuser;
</select>
</mapper>