/**
*
* @param ids '1,2,3'
* @return
*/
@Select("select * from user_info where id in (${ids})")
List<UserInfo> getUserbyIds(@Param("ids")String ids);
參數需要使用${}來引用,#{}不能識別。【這個方案貌似不起作用】
------------xml文件寫法
0
DELETE FROM DEMO
WHERE ID in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
---------------SQLProvider
public class Test { @SuppressWarnings("unchecked") public static String getTestQuery(Map<String, Object> params) { List<String> idList = (List<String>) params.get("idList"); StringBuilder sql = new StringBuilder(); sql.append("SELECT * FROM blog WHERE id in ("); for (String id : idList) { if (idList.indexOf(id) > 0) sql.append(","); sql.append("'").append(id).append("'"); } sql.append(")"); return sql.toString(); } public interface TestMapper { @SelectProvider(type = Test.class, method = "getTestQuery") List<Blog> selectBlogs(@Param("idList") int[] ids); } }