关于springboot找不到mapper.xml的解决办法

本文详细介绍了如何解决在使用MyBatis框架时遇到的'Invalid bound statement (not found)'错误,该错误通常发生在尝试调用未被正确加载的Mapper XML中的SQL语句时。解决方案涉及在Maven项目的pom.xml文件中正确配置资源,确保所有必要的XML文件,包括Mapper XML文件,都能被正确地包含和识别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

具体问题:
Invalid bound statement (not found): cn.hx.springboot.mapper.ItemsMapper.selectByPrimaryKey
解决办法:
在pom文件的build中加上以下内容

 <resources>
            <resource>
                <directory>src/main/java</directory>
                <!-- 此配置不可缺,否则mybatis的Mapper.xml将会丢失 -->
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <!--指定资源的位置-->
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/webapp</directory>
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>

成功解决

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值