mysql查询语句传递数组参数

需求描述:

      最近做一个报表项目,要求把几个id的值进行累加获取

问题分析:

    dao层传递的是数组:

    List<ZtMonthRateVo> findNewProjectMonthRate(List<Integer> list);

    在xml文件中参数也应该是List

    parameterType="java.util.List"

     然后sql语句是:

    select begin from zt_project where id in #{list}

     但是仅仅就这样写还是会报错,参数没有遍历

问题解决:

     正确sql语句如下

select begin from zt_project where id in 
     <foreach collection="list" item="id"  open="(" separator="," close=")"> 
           #{id} 
     </foreach>
发布了193 篇原创文章 · 获赞 30 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/yiye2017zhangmu/article/details/102547380