看接口。传入一个Long型的List。
int updateReadCount(@Param(value = "topicIdList") List<Long> topicIdList);
xml里面循环update.
<update id="updateReadCount" parameterType="java.util.List">
update CTS
set read_count = read_count + 1
where topic_id in
<foreach item="item" index="index" collection="topicIdList" open="(" close=")" separator=",">
#{item.topicId}
</foreach>
</update>
就是直接复制了别人的代码,改了一改。怎么都跑不通。。。。。。。
问题就出在这个item,item 表示集合中每一个元素进行迭代时的别名。
List<Long> topicIdList 因为时Long型(不是entity封装着的),就不需要别名了。改为如下就可以跑通了。
<update id="updateReadCount" parameterType="java.util.List">
update CTS
set read_count = read_count + 1
where topic_id in
<foreach item="topicId" index="index" collection="topicIdList" open="(" close=")" separator=",">
#{topicId}
</foreach>
</update>