Skip to content

Instantly share code, notes, and snippets.

@wataru420
Created January 13, 2012 12:29
Show Gist options
  • Save wataru420/1605876 to your computer and use it in GitHub Desktop.
Save wataru420/1605876 to your computer and use it in GitHub Desktop.
package jp.hoge.sql;
import java.util.List;
import jp.hoge.sql.User;
import org.apache.ibatis.annotations.SelectProvider;
public interface HogeMapper {
@SelectProvider(type=HogeProvider.class, method="makeSql")
List<User> findRankByIds(@Param("idList") List<String> idList);
}
package jp.hoge.sql;
import java.util.List;
import java.util.Map;
import static org.apache.ibatis.jdbc.SelectBuilder.*;
public class HogeProvider {
public static String makeSql(Map<String,Object> params) {
List<String> ids = (List<String>) params.get("idList");
BEGIN();
SELECT("id,nick_name,rank");
FROM("ranking");
boolean first = true;
for (String id : ids) {
if (first) {
first = false;
}else {
OR();
}
WHERE("id = '" + id + "'");
}
ORDER_BY("rank");
return SQL();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment