1 个回答
这里写接口简单,示例如下:

@GetMapping("/template")
public void downloadTemplate(HttpServletResponse response) throws IOException {
ClassPathResource resource = new ClassPathResource("apptag/sender_no_blacklist.xlsx");
if (!resource.exists()) {
throw BizException.of(ErrorCode.BAD_REQUEST, "未找到资源文件");
}
byte[] bytes = IoUtil.readBytes(resource.getInputStream(), true);
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("sender_no_blacklist.xlsx", StandardCharsets.UTF_8));
response.setHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
response.setContentType("application/octet-stream");
response.getOutputStream().write(bytes);
}
最后记得把这些地方修改下:
发布于:3小时前 IP属地:四川省
我来回答
您需要 登录 后回答此问题!
