spring+mybatic整合开发的常见问题

a、出现异常:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

 

 

 

 6、这是一个很容易忽视的点,记住:接口名与Mybatis的映射文件名一定要一模一样。如图:

 

 

 7、mybatis的mapper配置文件需放在resource文件夹下,如图:

 

 

 

 

 

 因为maven默认的   编译的时候   只搬运src/main/java里面的java文件到target/classes,其他文件会被忽略,resource文件夹下的就相当与src/main/java下

所以查看配置文件是否被加载了可查看target是否有mapper配置文件,如图:

 

 或是使用第二种方法解决(不需要改resource目录,更推荐):

解决办法就在maven的pom文件下增加配置   
<build>
<plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>copy-xmls</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
                        <outputDirectory>${basedir}/target/classes</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/java</directory>
                                <includes>
                                    <include>**/*.xml</include>
                                </includes>
                            </resource>
                        </resources>
                 </configuration>
          </execution>

        </executions>
      </plugin>
</plugins>
</build>
这样配置之后    idea在builde的时候   或者执行   maven  test  的时候   才能把源码文件夹里的xml文件与java文件一起搬到target/classes   里面去    
别人如果导入你的这个maven工程   也不用设置idea了

 转载至:https://bbs.csdn.net/topics/391841282?page=1#post-402070612

转载至:https://blog.csdn.net/sundacheng1989/article/details/81630370

 

 

 

 

 

 

posted @ 2020-04-17 02:25  shouyaya  阅读(147)  评论(0编辑  收藏  举报