zoukankan      html  css  js  c++  java
  • 仓库批量存储

    批量插入

    定义字段,方便调用

     <sql id="MaterialsInColumns">
          materialsId,materialsName,materialsType,unitName,unitId,classfiyName,
          classfiyId,saveLocation,saveLocationId,supplierId,
          materialsPrice,materialsNum,comment,inOrOut,itemId,materialsNumber,
          state,createDate,updateDate
        </sql>

    批量入库

    <!--产品入库-->
        <insert id="MaterialsIn" parameterType="com.wanqun.wisdomsitecloud.v1.code.bean.Materials">
            insert into m_materials(
            <include refid="MaterialsInColumns"/>
            )
            VALUES
            <foreach collection="list" item="temp" separator="," close=";">
                (#{temp.materialsId},
                #{temp.materialsName},
                #{temp.materialsType},
                #{temp.unitName},
                #{temp.unitId},
                #{temp.classfiyName},
    
                #{temp.classfiyId},
                #{temp.saveLocation},
                #{temp.saveLocationId},
                #{temp.supplierId},
    
                #{temp.materialsPrice},
                #{temp.materialsNum},
                #{temp.comment},
                1,
                #{temp.itemId},
                #{temp.materialsNumber},
                1,
                now(),
                now())
            </foreach>
        </insert>

    foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合。
    foreach元素的属性主要有 item,index,collection,open,separator,close。
    item集合中每一个元素进行迭代时的别名,
    index表示在迭代过程中,每次迭代到的位置,
    open该语句以什么开始,
    separator在每次进行迭代之间以什么符号作为分隔 符,
    close以什么结束,
    在使用foreach的时候最关键的也是最容易出错的就是collection属性,
    该属性是必须指定的,但是在不同情况 下,该属性的值是不一样的,
    主要有一下3种情况:
    1.     如果传入的是单参数且参数类型是一个List的时候,collection属性值为list
    2.     如果传入的是单参数且参数类型是一个array数组的时候,collection的属性值为array
    3.     如果传入的参数是多个的时候,我们就需要把它们封装成一个Map了

    原文链接:https://blog.csdn.net/sz15732624895/article/details/82892283

    批量插入加判断

     <insert id="insertExaminingDetails" parameterType="map">
            insert into m_examiningReportDetails(
            examiningReportDetailsId,
            fieldId,
            createDate,
            updateDate,
            fileClass,
            examiningReportId,
            resultId,
            resultInfo
            )
            VALUES
            <foreach collection="list" item="temp" separator="," close=";">
                (#{temp.examiningReportDetailsId},
                #{temp.fieldId},
                now(),
                now(),
                #{temp.fileClass},
                #{temp.examiningReportId}
                <choose>
                    <when test="temp.resultId != null and temp.resultId !=''">
                       , #{temp.resultId}
                    </when>
                    <otherwise>
                      , null
                    </otherwise>
                </choose>
                <choose>
                    <when test="temp.resultInfo != null and temp.resultInfo !=''">
                       , #{temp.resultInfo}
                    </when>
                    <otherwise>
                       , null
                    </otherwise>
                </choose>
    
                )
            </foreach>
    
        </insert>
    <select id = "" resultMap = "">
    
       select * from table
       <where>
              <if test="type == 'x1' ">
                   and  条件1;
             </if>
            <if test="type == 'x2' ">
                   and  条件2;
             </if>
       </where>
    
    </select>
  • 相关阅读:
    C#中的“装箱”与“拆箱”[转贴]
    C#中的委托和事件[转帖]
    ASP.NET的四种错误机制[转帖]
    读技术书的技巧
    《AdvancED ActionScript 3.0 Animation》读书笔记(2) —— 2.5d
    读《JavaScript大师Nicholas C. Zakas谈TypeScript》有感,也谈编译js问题
    《游戏人工智能编程》读书笔记 —— 向量的归一和点乘
    浏览器图形渲染性能测试
    对对碰游戏demo
    A星寻路demo
  • 原文地址:https://www.cnblogs.com/dk2557/p/12574878.html
Copyright © 2011-2022 走看看