Mapped Statements collection does not contain value for (命名空间+id)

本文详细解析了在使用MyBatis框架时遇到的MappedStatements集合未包含指定ID的异常问题,探讨了可能的原因,包括命名空间错误、XML映射文件未正确加载等,并提供了相应的解决方案。

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

我的异常信息:

Error updating database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.gx.mapper.AccountMapper.update
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.gx.mapper.AccountMapper.update

	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)

在刚开始使用mybatis的测试中,在mybatis的映射文件配置中配置如下

<mapper namespace="com.gx.mapper.AccountMapper">
    <select id="selectAll" resultType="com.gx.model.Account">
          select aid,aname,apass,a_nikename as anikename from account
    </select>
    <select id="selectById" resultType="com.gx.model.Account">
        select aid,aname,apass,a_nikename as anikename from account  where aid=#{aid}
    </select>
    <update id="update" parameterType="com.gx.model.Account">
        update account set apass=#{apass} where aid=#{aid}
    </update>
    <insert id="insert" parameterType="com.gx.model.Account">
        INSERT INTO account(aname,apass,a_nikename)
        VALUES(#{aname},#{apass},#{anikeName})
    </insert>
    <delete id="delete" parameterType="java.lang.Integer">
        delete from account where aid=#{aid}
    </delete>
</mapper>

其中包括了五个sql的编写。测试过程中只有第一个selectAll的时候正常,其他情况都会报

Mapped Statements collection does not contain value for (namespace+id)的异常信息。

百度搜索总结。这方面的问题通常原因有四种:

1.mybatis的映射文件的命令空间与接口的全限定名不一致;

2有可能mybatis的映射文件名字与接口的类名字不一致;

3.还有一种情况就是接口声明的方法在映射文件里面没有。

4.使用maven项目打包的时候,是不能够将java包里面的mybatis的映射文件进行打包处理。这个时候需要手动在pom.xml中进行配置

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

我这里是配置了两个资源。第一个是将java中的xml进行打包。但是之后发现resources目录下的资源文件没有被打包。所有我第二个是将

resources目录下的资源进行配置。

以上都没有解决的话,就只能是项目的代码没有被重新编译。使用maven 进行编译或打包。然后调试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值