解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题

即在mybatis中dao接口与mapper配置文件在做映射绑定的时候出现问题

简单说,就是接口与xml要么是找不到,要么是找到了却匹配不到

 1 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.youxiu.edu.mapper.UserMapper.findUserById
 2     at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:223)
 3     at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
 4     at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59)
 5     at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
 6     at com.sun.proxy.$Proxy18.findUserById(Unknown Source)

在生成的target内可以发现没有mapper.xml,解决方法是在Dao的pom内配置mybatis-plus(只有mybatis.mapper-locations不起作用)

如图:

代码:

 1 <plugin>
 2                     <artifactId>maven-resources-plugin</artifactId>
 3                     <version>3.0.2</version>
 4                     <executions>
 5                         <execution>
 6                             <id>copy-xmls</id>
 7                             <phase>process-sources</phase>
 8                             <goals>
 9                                 <goal>copy-resources</goal>
10                             </goals>
11                             <configuration>
12                                 <outputDirectory>${basedir}/target/classes</outputDirectory>
13                                 <resources>
14                                     <resource>
15                                         <directory>${basedir}/src/main/java</directory>
16                                         <includes>
17                                             <include>**/*.xml</include>
18                                         </includes>
19                                     </resource>
20                                 </resources>
21                             </configuration>
22                         </execution>
23                     </executions>
24                 </plugin>

 

如果以上方法解决不了,可以尝试在pom中添加如下代码:

1 <resources>
2       <resource>
3           <directory>src/main/java</directory>
4           <includes>
5               <include>**/*.xml</include>
6           </includes>
7       </resource>
8 </resources>

 

posted @ 2020-04-27 09:32  手下留情  阅读(1417)  评论(0编辑  收藏  举报