There is a query in my Mybatis containing an IN clause which is basically a set of Id\'s ( Integers)
I am now stuck on how can I pass an Integer array to this IN cla
YES, you can do that using annotations.
If you're using postgresql, you can do like in this post.
If you're using MySQL try this changes in your code sample:
Mybatis Method using Annotations
@Select(SEL_QUERY)
@Results(value = {@Result(property="id",column="ID")})
List getIds(@Param("usrIds") String usrIds);
Query (using MySQL)
select distinct ID from table a where FIND_IN_SET( a.id, #{usrIds}) <> 0
Method call
Integer[] arr = new Integer[2];
arr[0] = 1;
arr[1] = 2;
String usrIds= "";
for (int id : ids) {
usrIds += id + ",";
}
mapper.getIds(usrIds)