mybatis传List

1.mybatis传List查询的情况
<select id="selectProLedgerList" resultType="com.ssic.educateion.common.dto.ProLedgerDto"
        parameterType="java.util.List">
        SELECT a.wares_id AS waresId,b.ware_batch_no AS batchNo, b.start_address AS startAddress ,b.action_date as actionDate
        FROM t_pro_ledger a
        LEFT JOIN t_pro_ledger_master b ON a.master_id = b.id
        WHERE a.stat = 1 AND b.stat = 1
        <if test="waresIdList != null">
            and a.wares_id  in
         <foreach collection="waresIdList" item="id" index="index"
                open="(" close=")" separator=",">
                #{id}
         </foreach>
        </if>
        ORDER BY a.`create_time` DESC

</select>

Mybatis根据  in   List  查询
<if test="ledgerDto.waresNameList != null">
         and a.name  in
         <foreach collection="ledgerDto.waresNameList" item="name" index="index"
                open="(" close=")" separator=",">
                #{name}
         </foreach>
</if>


   mybatis传List插入的情况
<insert id="addNutritionalBatch" parameterType="java.util.List">  
  INSERT INTO t_pro_nutritional (id, package_id,name,unit,weight, create_time, stat)
  VALUES
    <foreach collection="list" item="item" index="index" separator="," >  
        (#{item.id},#{item.packageId},#{item.name},#{item.unit},#{item.weight},#{item.createTime},#{item.stat})  
    </foreach>

</insert>



猜你喜欢

转载自blog.csdn.net/jam_yin/article/details/52396255