zoukankan      html  css  js  c++  java
  • spring-boot下载

    // 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));
        }
    
    }
  • 相关阅读:
    windows 7中添加新硬件的两种方法(本地回环网卡)
    文档编辑大神
    BIOS Setup
    Sound Card Chip
    modem&NIC&sound card
    Monitor
    chassis & power
    HDD
    C#开发实例 鼠标篇
    编程之美 1.8小飞的电梯调度算法
  • 原文地址:https://www.cnblogs.com/xiaolei2017/p/8743763.html
Copyright © 2011-2022 走看看