介绍
怎么在springboot中利用vue实现在页面中下载文件?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
1。前端代码:
& lt; template v-slot:操作=皗},row “比; ,,& lt; vxe-button ,类=癳l-icon-download", title=俺晒略亍?circle @click=癲ownloadFile(行)“祝辞& lt;/vxe-button> & lt;/template> downloadFile(行),{=,window.location “http://localhost: 8001/文件/downloadFile ? taskId=? +, row.id; }
2。后端代码:
package com.gridknow.analyse.controller; import com.alibaba.fastjson.JSON; import com.gridknow.analyse.entity.DataInfo; import com.gridknow.analyse.service.FileService; import com.gridknow.analyse.utils.Download; import com.gridknow.analyse.utils.Result; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.InputStreamResource; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation。*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletResponse; import . io . *; import 并不知道; import java.util.Map;/* * ,* @ClassName FileController ,* @Description:待办事项 ,* @Author 管理员 ,* @Date 2020/8/20  14:02 ,* @Version TODO * */@ controller @RequestMapping (“/file") public class  FileController { ,@ value (“$ {gridknow.mltc.imgurl}“) ,private String  imgUrl; ,@ autowired ,private FileService  fileService; ,@CrossOrigin=,@RequestMapping (value “/upload",, method =, RequestMethod.POST) ,@ResponseBody ,public Result 上传(MultipartHttpServletRequest 请求),{ List<才能;MultipartFile>, multipartFiles =, request.getFiles (“file"); Map<才能,字符串,Object>, map =,(字符串,Map