【问题标题】:Spring Data JPA save list entity return list in same the order?Spring Data JPA保存列表实体返回列表的顺序相同?
【发布时间】:2018-05-20 15:46:39
【问题描述】:

Spring-Data-JPA 的CrudRepository 中的方法吗

 <S extends T> Iterable<S> saveAll(Iterable<S> entities)

以相同的顺序返回列表?

【问题讨论】:

标签: java spring jpa orm spring-data-jpa


【解决方案1】:

在那个版本中,实际的 List 是返回类型:

@Transactional
public <S extends T> List<S> save(Iterable<S> entities) {

    List<S> result = new ArrayList<S>();

    if (entities == null) {
        return result;
    }

    for (S entity : entities) {
        result.add(save(entity));
    }

    return result;
}

因此,如果您将 List 传递给该方法,您将获得与 ArrayList 是实现的顺序完全相同的结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-03
    • 2020-03-26
    • 2018-07-31
    • 2019-09-30
    • 1970-01-01
    • 2021-05-25
    • 2013-05-01
    • 1970-01-01
    相关资源
    最近更新 更多