MyBatis踩坑持续更新

Invalid bound statement (not found)错误

这里写图片描述
IDEA开发,其中xml文件放到resources中,接口定义在mapper包下,mybatis配置如下:
这里写图片描述
我们知道配置映射器用三种方式

<mapper resource="xml所在文件路径"/>
<mapper package = "mapper接口所在包名"/>
<mapper class= "接口全限定名"/>

但是此处只有第一种配置方式有效,很是纳闷,初步猜想是第二三种配置方式是需要接口和XML文件放在同一个文件夹下,而IDEA的扫描机制会忽略在java/main 中的xml文件会被忽略 ,这样的文件组织方式使得只能使用第一种方式。
果然,将mapper接口和xml文件放在一起,其中在pom文件中找到<build></build>

在其中添加以下几行,用于扫描到xml文件。

<resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
</resources>

然后第二三种配置方式都成功了~~~
参考博客:Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value
这里写图片描述
我们可以看到,使用Mybatis事务自动提交关闭,所以insert,update,delete需要显示commit

猜你喜欢

转载自blog.csdn.net/mdreamlove/article/details/80530818
今日推荐