赵计刚
每天进步一点点

mybatis实现in查询,两种方法:

  • xml形式(推荐)
  • 注解方式(个人喜欢注解,但是in场景可能不太适合注解)

代码:

1     @Select("<script>"
2               + "SELECT IDFA FROM t_xxx WHERE IDFA IN "
3               + "<foreach item='item' index='index' collection='strList' open='(' separator=',' close=')'>"
4                   + "#{item}"
5               + "</foreach>"
6           + "</script>")
7     @Results(value = { @Result(column = "user_name", property = "username") })
8     public List<String> getXxxList(@Param("strList") List<String> strList);
View Code

说明:上述方式其实是一种注解完全代替xml的方法。

其中的foreach的collection直接写成@param中的值即可。

posted on 2016-05-13 14:19  赵计刚  阅读(23344)  评论(0编辑  收藏  举报