zoukankan      html  css  js  c++  java
  • 【MyBatis】实现in操作符在WHERE 子句中规定多个值

    Mapper.xml中写:

        <select id="selectIdsByDate"  resultType="java.lang.Long">
            select id from emp where cdate&lt;#{date,jdbcType=TIMESTAMP} limit 10000
        </select>
        
        <delete id="deleteByIds">
            delete from emp where id in
            <foreach collection="list" open="(" close=")" separator="," item="id" index="i">
                #{id}
            </foreach>
        </delete>

    接口中这样写:

        List<Long> selectIdsByDate(String date);
        
        int deleteByIds(List<Long> ids);

    代码中则这样用:

                EmpMapper mapper=session.getMapper(EmpMapper.class);
                
                int totalChanged=0;
                int index=0;
                while(true) {
                    List<Long> ids=mapper.selectIdsByDate("2018-02-02");
                    if(ids.size()==0) {
                        break;
                    }
                    
                    int changed=mapper.deleteByIds(ids);
                    System.out.println("#"+index+" deleted="+changed);
                    session.commit();
                    totalChanged+=changed;
                    
                    index++;
                }

    --END-- 2019年10月14日09:30:52

  • 相关阅读:
    1、如何使用Azure Rest API创建虚拟机
    Ansible---2的Roles使用
    linux下的shell脚本
    生成器 yield和协程
    xshell
    markdown的使用
    加密
    Hbuilder打包app
    尾递归
    jupyter
  • 原文地址:https://www.cnblogs.com/heyang78/p/11669659.html
Copyright © 2011-2022 走看看