【报错解决:Parameter ‘id‘ not found. Available parameters are...】

报错解决:【通用异常:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘id’ not found. Available parameters are [dto, param1]】

报错内容:
在这里插入图片描述

报错原因:一般情况为业务层或Service中接口参数与mapper.xml中参数不一致导致。

boolean isExist(@Param("dto")MenuforimexDTO dto);
<select id="isExist" resultType="boolean" >
        select count(t.id)
        from menuforimex t
        <where>
            (t.code =#{code} or t.name =#{name})
            <if test="id != null and id !=''">
                and t.id != #{id}
            </if>
            and (current_date() >= t.start_date or t.start_date is null)
            and (t.end_date >= current_date() or t.end_date is null)
            and t.activity = true
        </where>
    </select>

比如我这里传的是实体对象,mapper中是直接写的字段,需要改为从实体对象中取字段数据,从而保持参数一致。
修改后:

<select id="isExist" resultType="boolean" >
        select count(t.id)
        from menuforimex t
        <where>
            (t.code =#{dto.code} or t.name =#{dto.name})
            <if test="dto.id != null and dto.id !=''">
                and t.id != #{dto.id}
            </if>
            and (current_date() >= t.start_date or t.start_date is null)
            and (t.end_date >= current_date() or t.end_date is null)
            and t.activity = true
        </where>
    </select>
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值