org.apache.ibatis.binding.BindingException: Parameter 'xxx' not found.

1. 情景重现

1.1 Mapper 代码

public interface DeviceFileInfoVOMapper {

    List<QueryFileDTO> selectVideoByField(String devId, Long chl,  Date startTime,  Date endTime, Pagination pagination);

}

1.2 XML 代码

  <select id="selectVideoByField"  resultMap="videoFileMap">
    SELECT file_id
    FROM t_device_file_info WHERE 1=1
    <trim>
      <if test="devId != null">
        AND dev_id=#{devId,jdbcType=VARCHAR}
      </if>
      <if test="chl != null">
        AND chl=#{chl,jdbcType=BIGINT}
      </if>
      <if test="startTime != null">
        AND start_time &gt;= #{startTime,jdbcType=TIMESTAMP}
      </if>
      <if test="endTime != null">
        AND end_time &lt;= #{endTime,jdbcType=TIMESTAMP}
      </if>
    </trim>
  </select>

1.3 错误详情

2. 解决方法

  在 Mapper 中定义的方法参数添加 @Param 注解,@Param 注解的值和xml中引用的参数名一致即可。

  @Param("devId"),则在xml中使用 #{devId}

public interface DeviceFileInfoVOMapper {

    List<QueryFileDTO> selectVideoByField(@Param("devId") String devId, @Param("chl") Long chl, @Param("startTime")  Date startTime, @Param("endTime") Date endTime, Pagination pagination);

}
原文地址:https://www.cnblogs.com/virgosnail/p/10831423.html