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;
}