1、在我用springboot+mytatis时,生成完mapper后,然后访问网站总是报错
错误信息:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.insurance.repository.MOperateLogMapper.selectByExample] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.insurance.repository.MOperateLogMapper.selectByExample
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:227)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:49)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
at com.sun.proxy.$Proxy64.selectByExample(Unknown Source)
at com.insurance.services.impl.OperateLogService.getDataGridDataByCondition(OperateLogService.java:37)
at com.insurance.backend.controller.LogOperateController.getDataGridDataByCondition(LogOperateController.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
经过排查,发现是classpath(即表示target下的classses文件夹)下,没有生成mapper.xml
2、解决,在repository项目的pom文件中,加上build resources即可,如图
生成结果
最后要想能运行,还要配置MapperScan的扫描基础包
3、延伸
(1)、filtering
我自己实践中的一个例子:
当此filtering为true时,结果竟是
这表明,当设置了filtering为true时,<directory>src/main/resources</directory>文件夹下的文件,如某些js呀等等,可能被application.yml中配置的某些变量替代了
所以,没有特别需求, 应该不对build-resources下的<directory>src/main/resources</directory>进行设置;或者如果进行设置,让filtering为false最好
(2)、pom文件中的,build-resources,如果不进行特殊设置,默认会按如下图描述方式;
对<directory>src/main/resources</directory>来说,如果进行了设置,就会按照设置的进行,例:
对<directory>src/main/java</directory>来说,即使进行了设置(当然是不进行排除.class文件设置),也会把默认的编译后.class文件放到classpath中