zoukankan      html  css  js  c++  java
  • mybatis之动态SQL操作之删除

    /**
     * 持久层
     */
    public class StudentDao {
        /**
         * 动态SQL--删除
         */
        public void dynaSQLwithDelete(int... ids) throws Exception{
            SqlSession sqlSession = MyBatisUtil.getSqlSession();
            try{
                sqlSession.delete("mynamespace.dynaSQLwithDelete",ids);
            }catch(Exception e){
                e.printStackTrace();
                sqlSession.rollback();
                throw e;
            }finally{
                sqlSession.commit();
                MyBatisUtil.closeSqlSession();
            }
        }
        public static void main(String[] args) throws Exception{
            StudentDao dao = new StudentDao();
            dao.dynaSQLwithDelete(1,3,5,7);
        }
    }

    StudentMapper.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
    <mapper namespace="mynamespace">
        <!-- item表示迭代的参数 -->
        <delete id="dynaSQLwithDelete">
            delete from students where id in
            <!-- 
            <foreach collection="array" open="(" close=")" separator="," item="ids">
                ${ids}
            </foreach>
            -->    
            <foreach collection="list" open="(" close=")" separator="," item="ids">
                ${ids}
            </foreach>    
        </delete>    
    </mapper>
  • 相关阅读:
    【SR】MAP
    【SR】Example-based
    【SR】论文资源相关
    【SR】正则化超分辨率复原
    词汇累记
    单模光纤与多模光纤的实际使用
    光纤中的光波长
    数码相机常用CCD/CMOS尺寸对比
    尼康D90多点对焦
    Python3.x:日期库dateutil简介
  • 原文地址:https://www.cnblogs.com/loaderman/p/10064465.html
Copyright © 2011-2022 走看看