Hướng dẫn read excel file java spring boot - đọc file excel java khởi động mùa xuân
Cách đọc tệp excel trong khởi động mùa xuân Show
Vui lòng nhấp vào liên kết sau để tải xuống dự án mẫu. Đọc tệp excel trong dự án mẫu khởi động mùa xuân (483 lượt tải xuống) Cách đọc tệp excel trong khởi động mùa xuânVui lòng làm theo các bước sau để biết cách đọc tệp Excel trong Spring Boot 1) Đầu tiên tạo một dự án Maven đơn giản và khởi động khởi động Spring Boot và Apache POI được hiển thị bên dưới
2) Bây giờ hãy tạo RestControll để đọc tệp Excel được hiển thị bên dưới package com.example.SpringBootExcelReader; import java.io.IOException; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController public class ExcelController { @PostMapping("excel") public String excelReader(@RequestParam("file") MultipartFile excel) { try { XSSFWorkbook workbook = new XSSFWorkbook(excel.getInputStream()); XSSFSheet sheet = workbook.getSheetAt(0); for(int i=0; i Tệp Excel là định dạng tệp bảng tính do Microsoft tạo để sử dụng với Microsoft Excel. Bạn có thể sử dụng tệp để tạo, xem, chỉnh sửa, phân tích dữ liệu, biểu đồ, ngân sách và nhiều hơn nữa. Trong hướng dẫn này, tôi sẽ chỉ cho bạn cách tải lên/nhập dữ liệu tệp Excel vào cơ sở dữ liệu MySQL bằng Spring Boot & Apache POI, sau đó xuất API REST để trả lại tệp Excel từ bảng cơ sở dữ liệu. Bài viết liên quan: - Ví dụ tải lên tệp Multiart Spring Boot Triển khai: - Triển khai ứng dụng khởi động mùa xuân trên AWS - Beanstalk đàn hồi - Docker Compose: Spring Boot và MySQL Ví dụ Nội dung
API REST Boot Boot để tải lên các tệp excelAPI REST BOOT REST TRẢ LẠI Tệp Excel.xlsx file that contains Tutorial data as following: Công nghệ
Xác định mô hình dữ liệu Tạo kho lưu trữ dữ liệu để làm việc với cơ sở dữ liệu API REST BOOT REST TRẢ LẠI Tệp ExcelCông nghệtutorials.xlsx that contains data in MySQL table: Cấu trúc dự án
Thiết lập dự án tải lên tệp excel khởi động mùa xuân Định cấu hình DataSource Spring, JPA, Hibernate
Công nghệ
Cấu trúc dự ánThiết lập dự án tải lên tệp excel khởi động mùa xuân Định cấu hình DataSource Spring, JPA, Hibernate Xác định mô hình dữ liệututorials. package com.example.SpringBootExcelReader; import java.io.IOException; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController public class ExcelController { @PostMapping("excel") public String excelReader(@RequestParam("file") MultipartFile excel) { try { XSSFWorkbook workbook = new XSSFWorkbook(excel.getInputStream()); XSSFSheet sheet = workbook.getSheetAt(0); for(int i=0; i |