报错解决:【通用异常: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>
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐