mybatis批量操作

 

mybatis 批量插入原子服务:

	int batchSave(List categorys);
	@Override
	public int batchSave(List categorys) {
		return storeCategorysMapper.batchSave(categorys);
	}

重点是mybatis的批量插入xml:

    int batchSave(List categorys );
  
    insert into store_categorys(store_category_id, store_id, store_code,
    store_name, display_contact, category_code,
    parent_category_code, category_name, category_level,
    state, create_oper_id, create_time,
    update_oper_id, update_time, remark,
    ext_json) values
    
      (#{item.storeCategoryId,jdbcType=BIGINT}, #{item.storeId,jdbcType=VARCHAR}, #{item.storeCode,jdbcType=VARCHAR},
      #{item.storeName,jdbcType=VARCHAR}, #{item.displayContact,jdbcType=VARCHAR}, #{item.categoryCode,jdbcType=VARCHAR},
      #{item.parentCategoryCode,jdbcType=VARCHAR}, #{item.categoryName,jdbcType=VARCHAR}, #{item.categoryLevel,jdbcType=VARCHAR},
      #{item.state,jdbcType=VARCHAR}, #{item.createOperId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
      #{item.updateOperId,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP}, #{item.remark,jdbcType=VARCHAR},
      #{item.extJson,jdbcType=LONGVARCHAR})
    
  

mybatis的批量修改原子服务:

	int batchUpdate(List categorys);
	@Override
	public int batchUpdate(@Param("list")List categorys) {
		return storeCategorysMapper.batchUpdates(categorys);
	}
    int batchUpdates(List categorys);
  
    update store_categorys
    SET state =
    
      when #{item.storeCategoryId} then #{item.state}
    
    , update_time =
    
      when #{item.storeCategoryId} then #{item.updateTime}
    
    where store_category_id in (
    
      #{item.storeCategoryId}
    
    )
  

 

你可能感兴趣的:(小何童鞋的成长)