MyBatis注解select in参数

/**
 * 
 * @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);
        }
    }
原文地址:https://www.cnblogs.com/Dhouse/p/5853102.html