Created
January 13, 2012 12:29
-
-
Save wataru420/1605876 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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