第二章 mybatis使用注解實現in查詢(mysql),mybatismysql
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中的值即可。