相信大家或多或少都遇到过这个报错
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): org.example.mapper.BookMapper.list
这个报错一般是xml文件位置存放错误了或者程序无法扫描到xml文件。
之前一直没弄明白,现在弄明白了,分享给大伙避坑
四种存放方式
- xml文件放在resources下
- xml文件放在resources下
- xml文件放在resources下(1,2,3有点不同,下面详细介绍)
- xml文件放在mapper文件夹下
第一种(这种是最方便的)
xml文件所处文件夹是mapper,mapper接口所处文件夹是org.example.mapper,这时候不用配置pom.xml和mybatis-plus.mapper-locations
第二种(这个写得有点绕)
xml文件所处文件夹是org.example.xml,mapper接口所处文件夹也是org.example.xml,这个跟1不同,这个xml文件所处文件夹不是mapper,所以不能像1那样直接放在xml文件夹下,而是需要跟mapper接口的父级文件夹完全一致,即org.example.xml,这种方法也是不需要配置pom.xml和mybatis-plus.mapper-locations
第三种
这种xml文件所处文件夹是xml,mapper接口所处文件夹是org.example.mapper,这种则需要配置mybatis-plus.mapper-locations=classpath:xml/*.xml
第四种(这个有点麻烦)
这种xml文件所处的文件夹放在mapper文件夹下,需要配置
mybatis-plus.mapper-locations=classpath:org/example/mapper/xml/*.xml
pom.xml中也需要配置,<build></build>中的配置