春季启动JPA:使用库为MySQL批量加载数据 [英] Spring boot JPA: Use library to Bulk load data for MySQL

查看:99
本文介绍了春季启动JPA:使用库为MySQL批量加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring Boot的新手.

I'm fairly new to Spring boot.

我当前正在编写一个小型微服务,该服务将从CSV文件中批量加载数据到MySQL数据库表中.我知道有很多方法可以实现这一目标,但是我想到的方法之一就是使用MySQL LOAD DATA FILE命令来解析csv文件并将数据加载到数据库表中.

I'm currently writing a small microservice which will bulk load data from a CSV file into a MySQL database table. I understand that there are many ways to achieve this, but one of the ways I was thinking was to use the MySQL LOAD DATA FILE command to parse the csv file and load the data into the database table.

我想知道是否有人知道我可以使用Spring boot JPA库调用MySQL LOAD DATA命令的方法吗?

I was wondering if anyone knows of a way that I can invoke the MySQL LOAD DATA command using the Spring boot JPA library ?

任何帮助/建议都值得赞赏.

Any help/ advice is appreciated.

谢谢

推荐答案

找到了解决问题的方法:

Found a solution to the problem:

在存储库中的方法中添加@Modifying@Transactional批注.这是一个示例:

Add the @Modifying and @Transactional annotations to your method in the Repository. Here is an example:

@Repository
public interface ExpenseRepository extends CrudRepository<Expense, Integer>{

    @Modifying
    @Transactional
    @Query (value="LOAD DATA LOCAL INFILE 'C:/Users/Tester/Documents/transaction_data.txt' INTO TABLE tbl_fin FIELDS TERMINATED BY ',' IGNORE 1 LINES", nativeQuery = true)
    public void bulkLoadData();

}

这篇关于春季启动JPA:使用库为MySQL批量加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆