需求描述:
最近做一个报表项目,要求把几个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>