<select id="getcount" parameterClass="java.util.ArrayList" resultClass="int"> select count(id) from `user` where id in <iterate open="(" close=")" conjunction="," > #[]# </iterate> and status=1 </select>
程序调用的方式
public Integer getcount(List<Integer> friendsIds) throws SQLException { Integer count=(Integer)client.queryForObject("User.getcount", friendsIds); return count; }
还可以在程序把list拼成String,用string当参数传给Ibatis查询,但是要注意在Ibatis的xml中要用 $parameter$来取参数,以保证Ibatis不改变参数的性质,如果用#parameter#取参数,此种传参的办法就不行了
select count(id) from `user` where id in ($parameter$)