问题1:Invalid bound statement (not found): com.xxx.xxx.XxxMapper.selectByExample…
分析,一般出现这个可能是两个原因造成的
1. mapper.xml的命名空间(namespace)是否跟mapper接口的包名一致?比如,你接口的包名是com.name.mapper,接口名是Mapper.java,那么你的Mapper.xml中的namespace应该是com.name.mapper.Mapper
2. Springboot没有扫描到你的mapper.xml文件
踩坑:
我仔细检查了包名,namespace。首先不是第一个的问题
然后思考第二个原因,我的包结构如下。mapper.xml文件在resources文件夹下
我的配置如下:
#配置mybatis
mybatis.mapper-location=classpath*:mapper/*.xml
这时我的重点一直在等于号后面的地址,按照网上的方法试了很多次都不行。
接着我将我的mapper.xml放在和mapper接口同一个文件夹中,这时就好用,不再报错。
于是更加确信了我肯定是哪里配置不对导致的没有扫描到mapper.xml。
于是在我研究了一番,终于找到问题所在并作出修改。
原配置如下:
#配置mybatis
mybatis.mapper-location=classpath*:mapper/*.xml
修改后配置:
#配置mybatis
mybatis.mapper-locations=classpath*:mapper/*.xml
结论:
是mapper-locations而不是mapper-location,就差一个s,多么痛的领悟。折腾我这么久。