解決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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM