天天看點

mybatis批量操作資料

批量查詢語句:

List<MoiraiProductResource> selectBatchInfo(List<Long> idList);      
<!-- 批量查詢 -->
  <select id="selectBatchInfo" parameterType="java.util.List" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from moirai_product_resource
    WHERE PRODUCT_ID IN
    <foreach collection="list" open="(" close=")" separator="," item="item" index="index">
      #{item}
    </foreach>
  </select>      

批量插入:

int insertBatchInfo(List<MoiraiProductResource> listMoiraiProductResource);      
<!-- 批量添加 -->
  <insert id="insertBatchInfo" parameterType="java.util.List">
    insert into moirai_product_resource (PRODUCT_RESOURCE_ID, PRODUCT_ID, RESOURCE_ID,
    CREATETIME, CREATER)
    values
    <foreach collection="list" item="item" index="index" separator="," >
      (#{item.productResourceId,jdbcType=BIGINT}, #{item.productId,jdbcType=BIGINT}, #{item.resourceId,jdbcType=BIGINT},
      #{item.createtime,jdbcType=BIGINT}, #{item.creater,jdbcType=VARCHAR})
    </foreach>
  </insert>