MyBatis异常总结

1 Invalid bound statement

1 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.e3mall.search.mapper.ItemMapper.getItemList

事故现场

事故原因

接口和实现类不在同一个目录下面,找不到映射文件导致的。

此异常的原因是由于 mapper 接口编译后在同一个目录下没有找到 mapper 映射文件而出现的。由于 maven 工程在默
认情况下 src/main/java 目录下的 mapper 映射文件是不发布到 target 目录下的。

事故解决

在 e3-search-service工程的 pom 文件中添加如下内容

告知在src/main/java和src/main/resources下面都有配置文件。

<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<build>
    <resources>
           <resource>
               <directory>src/main/java</directory>
               <includes>
                   <include>**/*.properties</include>
                   <include>**/*.xml</include>
               </includes>
               <filtering>false</filtering>
           </resource>
           <resource>
               <directory>src/main/resources</directory>
               <includes>
                   <include>**/*.properties</include>
                   <include>**/*.xml</include>
               </includes>
               <filtering>false</filtering>
           </resource>
       </resources>
</build>
原文地址:https://www.cnblogs.com/jepson6669/p/9147557.html