您的位置:首页 > 数据库 > MySQL

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

2016-12-29 00:00 459 查看
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中的值即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: