【问题标题】:Getting the Data as a CSV file directly instead of a List of object from spring-data-jpa直接将数据作为 CSV 文件获取,而不是从 spring-data-jpa 获取对象列表
【发布时间】:2020-05-30 02:47:54
【问题描述】:

是否有可能以 CSV 数据的形式从 spring-data JPA 中获取数据,而不是 ArrayList of pojos like

下面是扩展JpaRepository的接口。

public interface FactAggRepository extends JpaRepository<FactAggRepository,Integer> {

@Query("select p from FactAggRepository as p where p.pId=:pId and p.periodStart=:periodStart")
public List<FactAggRepository> getAggregates(@Param("pId") Long pId,@Param("periodStart")LocalDateTime periodStart);

@Query("select p from UsageAgg as p where p.pId=:pId")
public List<UsageAgg> UsageAggregates(@Param("pId") Long pId);

}

自动装配存储库以使用以下相同的方法。

fetchedRecord = AggRepo.getAggregates(pId, periodStart);

现在上面的代码返回了列表。是否可以在不进行任何转换的情况下获取包含列表中数据的 CSV 文件。请告诉我。提前致谢。

【问题讨论】:

    标签: oracle csv jpa java-8 spring-data-jpa


    【解决方案1】:

    Spring Data 用于处理与数据源层的通信。不幸的是,CSV 不是原生处理的数据存储。

    您必须使用第三方依赖项(例如 OpenCSV)将这些 POJO 转换为 CSV。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-22
      • 2013-03-07
      • 1970-01-01
      • 2018-08-13
      • 2020-03-11
      • 1970-01-01
      • 2019-09-05
      • 2017-10-05
      相关资源
      最近更新 更多