sql语句使用foreach报错
生活随笔
收集整理的這篇文章主要介紹了
sql语句使用foreach报错
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
mapper
List<ReworkDeviceDetailDTO> getListByPartIds(List<Long> partIds);sql語句
<select id="getListByPartIds" resultType="com.dep.pms.entity.dto.ReworkDeviceDetailDTO">......where ptm.state = 0and 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="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;}總結
以上是生活随笔為你收集整理的sql语句使用foreach报错的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mybatis报错,找不到对应mappe
- 下一篇: 事物的开始和结束命令分别是什么_Auto