如果你的mapper接口和mapper.xml不在一个文件夹,继续往下看,如果在,直接关闭这个页面吧,对你没有帮助的
出现这个报错最根本的问题mapper接口和mapper.xml不在一个文件夹。
Mapper.xml与Mapper.class在同一个包下且同名,spring扫描Mapper.class的同时会自动扫描同名的Mapper.xml并装配到Mapper.class,问题就出在这里。
解决方法
使用配置文件配置的:
去spring和mybatis整合文件中加入
msc.setBasePackage("net.f3322.lingwl13.mapper");
return msc;
}
public Resource[] resolveMapperLocations(){
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
List mapperLocations = new ArrayList<>();
mapperLocations.add("classpath*:net.f3322.lingwl13.mapper/*.xml");
List resources = new ArrayList();
if (!CollectionUtils.isEmpty(mapperLocations)) {
for (String mapperLocation : mapperLocations) {
try {
Resource[] mappers = resourceResolver.getResources(mapperLocation);
resources.addAll(Arrays.asList(mappers));
} catch (IOException e) {
e.printStackTrace();
}
}
}
return resources.toArray(new Resource[resources.size()]);
}
感谢三位大佬铺路
Java书签 #MyBatis之setMapperLocations配置多个mapper路径的两种方法详解_有时有味的博客-CSDN博客_setmapperlocations
mybatis之mapperLocations配置的问题_进击的攻城狮-zxc的博客-CSDN博客_mybatis.mapper-locations不起ssm中Invalid bound statement (not found)错误的处理(IDEA中)_si_ma_tong_ming的博客-CSDN博客