今天在搭建springcloud项目时,发现如上错误,顺便整理一下这个异常:
1. mapper.xml的命名空间(namespace)是否跟mapper的接口路径一致
<mapper namespace="com.baicun.springcloudprovider.mapper.SysUserMapper">
2.mapper.xml接口名是否和mapper.java接口名一致
mapper.java --> SysUser selectById(@Param("id") Integer id);mapper.xml --> <select id="selectById" parameterType="java.lang.Integer" resultType="com.baicun.bean.SysUser">
3. 查看target.classes包下有没有生成mapper.xml文件,如果没有:
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
4.mapper类和mapper.xml不在同一个路径下时,application.yml文件需要配置 mapper-locations
mybatis: mapper-locations: classpath:mapper/*.xml