zoukankan      html  css  js  c++  java
  • mybatis 批量插入值的sql

    <insert id="insertAwardPic" useGeneratedKeys="true" parameterType="java.util.List">
    <selectKey resultType="long" keyProperty="id" order="AFTER">
    SELECT
    LAST_INSERT_ID()
    </selectKey>
    insert into check_awardspics
    (award_id,picurl,create_date)
    values
    <foreach collection ="list" item="CheckAwardspics" index= "index" separator =",">
    (#{CheckAwardspics.awardId},#{CheckAwardspics.picUrl},now())
    </foreach>
    </insert>

    ========================================================

    public int insertAwardPic(List<CheckAwardspics> checkAwardspicsList);

    /**
    * 添加奖品的图片
    * @param checkAwardspics
    * @return
    */
    public int insertAwardPic(List<CheckAwardspics> checkAwardspicsList){
    int count=0;
    try{
    count=checkAwardspicsDao.insertAwardPic(checkAwardspicsList);
    }catch(Exception e){
    logger.error("添加奖品的图片出现异常! e:"+e);
    }
    return count;
    }

    =================================================

    //批量插入数据图片
    CheckAwardspics checkAwardspics=null;

    if(StringUtils.isNoneEmpty(picUrl)){
    HashSet hset = new HashSet(Arrays.asList(picUrl));
    Iterator i = hset.iterator();
    while(i.hasNext()){
    checkAwardspics=new CheckAwardspics();
    checkAwardspics.setAwardId(checkAwardsB.getId());
    checkAwardspics.setPicUrl(String.valueOf(i.next()));
    checkAwardspicsList.add(checkAwardspics);
    }

    }

    =================================================================

    if(!checkAwardspicsList.isEmpty()&&checkAwardspicsList.size()>0){
    awardRecordService.deletePics(String.valueOf(checkAwardsB.getId()));//插入图片的时候先将原来的图片清空
    countB=awardRecordService.insertAwardPic(checkAwardspicsList);
    }

  • 相关阅读:
    【WPF】数据验证
    CSS 属性:touch-action
    sublime text3 中设置默认浏览器,并且设置快捷键
    Git克隆、修改、更新项目,及查看项目地址命令
    监听文本框输入oninput和onpropertychange事件
    css基础笔记
    纯css,div隐藏滚动条,保留鼠标滚动效果。
    打印机如何取消打印任务
    git使用上
    Git设置记住账号密码
  • 原文地址:https://www.cnblogs.com/austinspark-jessylu/p/6117836.html
Copyright © 2011-2022 走看看