mapper
List<ReworkDeviceDetailDTO> getListByPartIds(List<Long> partIds);
sql语句
<select id="getListByPartIds" resultType="com.dep.pms.entity.dto.ReworkDeviceDetailDTO">
......
where ptm.state = 0
and ppms.id in
<foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
报错
Servlet.service() for servlet [dispatcherServlet] in context with path [/pms-api] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'ids' not found. Available parameters are [collection, list]] with root cause org.apache.ibatis.binding.BindingException: Parameter 'ids' not found. Available parameters are [collection, list]
解决方法
将
<foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
改成
<foreach collection="list" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
具体原因不清楚
如果mapper中的参数改成对象的话,无论是<foreach collection="list"还是<foreach collection="ids"都可以查询成功
@Data
public class ReworkDeviceDetailFindReq {
private List<Long> ReworkIds;
}
博客内容涉及MyBatis动态SQL中参数未找到的问题,具体表现为在使用<foreach>标签遍历List参数时出现异常。错误信息指出'ids'参数未找到,但通过将'ids'改为'list'后问题得到解决。当Mapper接口参数为对象时,无论使用'ids'还是'list'都能正常查询。这可能是由于传入参数名称不一致导致的配置错误。

1万+

被折叠的 条评论
为什么被折叠?



