@GetMapping("/export")
public void toList(HttpServletResponse response) throws UnsupportedEncodingException {
List<Goods> list = new ArrayList<Goods>();
for (int i = 0; i < 50; i++) {
Goods g = new Goods();
g.setId(Long.parseLong((1 + i) + ""));
g.setGoodsDetail("aaaa" + i);
g.setGoodsImg("http///" + i);
g.setGoodsName("商品" + i);
g.setGoodsStock(i);
list.add(g);
}
ExcelWriter writer = ExcelUtil.getWriter();
writer.addHeaderAlias("id", "id");
writer.addHeaderAlias("goodsImg", "图片");
writer.addHeaderAlias("goodsName", "商品名");
writer.merge(5, "商品表");
writer.write(list, true);
response.setContentType("application/vnd.ms-excel;charset=utf-8");
String name = "test";
response.setHeader("Content-Disposition", "attachment;filename=" + name + ".xls");
ServletOutputStream out = null;
try {
out = response.getOutputStream();
writer.flush(out, true);
} catch (
IOException e) {
e.printStackTrace();
} finally {
writer.close();
}
IoUtil.close(out);
}