第二章 mybatis使用注解实现in查询(mysql)

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中的值即可。

原文地址:https://www.cnblogs.com/java-zhao/p/5489269.html