我这里只写mapper文件中的方法以及sql,其它层的请自行补充完整
注解版的mybatis的 in 的用法
@Select("<script> select recorder_no from page_element_config_record WHERE company_code IN " +
"<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'> #{item} </foreach> group by recorder_no order by count(recorder_no) desc limit 2 </script>")
List<String> selectCount(@Param("ids") List<Integer> ids);
说明:1.使用 in 的时候,sql语句必须包含在中,
2.item:给集合遍历取一个变量名,类似增强 for 循环中起的临时变量。
3.index:在list和数组中,index是元素的序号,在map中,index是元素的key
4.collection:程序传过来的值的集合,要做foreach的对象,就是mapper方法中的形参名
5.open:foreach代码的开始符号
6.close:foreach代码的结束符号
7.separator:元素之间的分隔符,上述一“,”分割
8.方法参数中的 @Param 这个注解必须使用,否则会报找不到xxxx
我这里的要求是按照取出数量前两位的 recorder_no