// Spring-boot 下载package com.csf.executor.word.controller;import com.aug3.sys.rs.response.RespObj;import com.csf.executor.word.common.enums.DICTTYPE;import com.csf.executor.word.service.WordService;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.core.io.FileSystemResource;import org.springframework.http.HttpHeaders;import org.springframework.http.MediaType;import org.springframework.http.ResponseEntity;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import java.io.File;import java.io.IOException;@RestController@RequestMapping("/word")public class WordController extends BaseController { private static final Logger LOGGER = LoggerFactory.getLogger(BaseController.class); @Autowired private WordService wordService; @GetMapping("/record/list") public RespObj listRecord() { return build(wordService.listRecord()); } @GetMapping("/download") public ResponseEntity download(String type) { LOGGER.info("Param type is {}", type); if (!DICTTYPE.contains(type)) { LOGGER.error("Param type is invalid"); return null; } File file = null; try { file = wordService.getDictFile(type); // zip包 } catch (Exception e) { LOGGER.error("Download zip file is error:", e); return null; } HttpHeaders headers = new HttpHeaders(); headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); String fileName = "dict_db_" + System.currentTimeMillis() + ".zip"; headers.add("Content-Disposition", "attachment; filename=" + fileName); headers.add("Pragma", "no-cache"); headers.add("Expires", "0"); return ResponseEntity .ok() .headers(headers) .contentLength(file.length()) .contentType(MediaType.parseMediaType("application/octet-stream")) .body(new FileSystemResource(file)); }}