Bulk storage warehouse

Bulk Insert

Custom fields, easy call

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

Bulk storage

<!--产品入库-->
    <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 is mainly used in building in conditions that can be iterated in a set of SQL statements.
foreach element attribute mainly item, index, collection, open, separator, close.
iterating alias item set each element,
index represents the iterative process, each iteration of the location,
Open what the statement begins,
Separator each iteration performed between what the symbol as a delimiter,
Close to What is the end,
when using foreach of the most critical and most error-prone is a collection property,
the property must be specified, but under different circumstances, the value of the property is not the same,
there are about three situations:
1 If a single-pass type and the parameter is a parameter when List, collection attribute value of List
2. If one parameter is passed and the time parameter is an array type array, collection of property value array
3. If incoming parameter is more, we need to package them into a Map of the

original link: https: //blog.csdn.net/sz15732624895/article/details/82892283

Guess you like

Origin www.cnblogs.com/dk2557/p/12574878.html