Springboot利用poi导出excel下载
2020-12-13 04:44
标签:index catch cells puts 文档 public framework xlsx exports 因为项目中之前的做法是用反射获取属性,所以demo中也是用的反射,我看网上很多文章都是存入一个List中,不知道这两种哪种更何合适一点,或者有什么更好的方法也请大佬们赐教。 Springboot利用poi导出excel下载 标签:index catch cells puts 文档 public framework xlsx exports 原文地址:https://www.cnblogs.com/n031/p/11119764.htmlSpringboot利用poi导出excel下载
pom
Service
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class StudentService {
public List
Controller
import lombok.Cleanup;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
@RestController
public class StudentController {
@Autowired
public StudentService studentService;
@RequestMapping("/exportStudentExcel")
public ResponseEntity
ExcelUtils
public class ExcelUtils {
/**
* 创建excel文档
*
* @param getters list中map的key数组集合
* @param headers excel的列名
*/
public static Workbook createWorkBook(List list, String[] getters, String[] headers, Class clazz) {
List