【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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM