Parameter 'id' not found. Available parameters are [0, 1, 2, param3, param1, param2]

本文介绍了一种在MyBatis中使用动态SQL时传递多个参数的方法,通过在Mapper.xml文件中调整参数引用的方式,实现了更为灵活的数据更新操作。

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

解决的方法很简单

先说第一种

DAO层的函数方法   

PublicUser selectUser(String imgURL,String id);
对应的Mapper.xml
<sql id="updateByPo1">
        <trim prefix="set" suffixOverrides=",">
            <if test="_parameter!= null">
                imgURL = #{imgURL},
            </if>
            </trim>
            </sql>

 <update id="savePhoto" parameterType="String">
        update customer_account_info//表名
        <include refid="updateByPo1"/>
        where id = #{id}
    </update>


修改后

<sql id="updateByPo1">
        <trim prefix="set" suffixOverrides=",">
            <if test="_parameter!= null">
                imgURL = #{0},
            </if>
            </trim>
            </sql>

 <update id="savePhoto" parameterType="String">
        update customer_account_info//表名
        <include refid="updateByPo1"/>
        where id = #{1}
    </update>

其中,#{0}代表接收的是dao层中的第一个参数,#{1}代表dao层中第二参数,更多参数一致往后加即可。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值