所用到的各种类,依赖的话百度一下吧,最后再给上全部代码
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.domain.MagBackAmountInfo;
import com.domain.ReturnResult;
import com.example.service.impl.MagBackAmountInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
导出数据为excel的接口代码
@GetMapping("/testExport")
public void test(HttpServletRequest request, HttpServletResponse response){
int pageStart = Integer.parseInt(request.getParameter("Pagenumber"));
int pageSize = Integer.parseInt(request.getParameter("number"));
/** 这里写你自己获取数据的方法*/
List<MagBackAmountInfo> magBackAmountInfos = backAmountInfoService.selectByPrimarybyid(null);
ExcelWriter writer = ExcelUtil.getWriter(true);
/** 这里的作用是将你的字段与excel展示名称做匹配 */
Map<String,String> map = new HashMap<>();
map.put("backAmountId","VIN");
map.put("makeInvocId","ICCID");
map.put("customerName","客户名称");
map.put("vehiclesName","车系名称");
map.put("vehicleModel","车型名称");
map.put("vehicleConf","配置名称");
map.put("customerType","客户类型");
map.put("activedTime","实销通过日期");
map.put("realStatus","实名状态");
writer.setHeaderAlias(map);
/** 这里的作用时,写出之后不展示你的字段名,只展示你设置的别名,客户类型,实销通过日期。这些 */<