zoukankan      html  css  js  c++  java
  • 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);
            }
        }
  • 相关阅读:
    OSError: cannot open resource(pillow错误处理)
    boost 库中文教程
    博客案例
    requests模块
    浅析Python中的struct模块
    面试基础知识点总结
    ant安装、环境变量配置及验证
    TestNG学习-001-基础理论知识
    selenium 常见面试题以及答案
    HTML5
  • 原文地址:https://www.cnblogs.com/Dhouse/p/5853102.html
Copyright © 2011-2022 走看看