java把网络xlsx下载到本地,java怎么导出xlsx文件
在SpringMVC的开发过程中,有时需要实现文档的下载功能。word,excel,pdf作为大家最常用的办公程序,它的文件传输就显得尤为重要,本文通过使用spring 提供的Resource封装来实现实现word/xlsx/pdf文件下载功能。话不多说。
o
package com.davidwang456; importjava.io.File; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importorg.springframework.core.io.FileSystemResource; importorg.springframework.core.io.Resource; importorg.springframework.web.bind.annotation.RequestMapping; importorg.springframework.web.bind.annotation.RequestMethod; importorg.springframework.web.bind.annotation.ResponseBody; importorg.springframework.web.bind.annotation.RestController; @RestControllerpublicclassDownloadController{ privatestaticfinalStringAPPLICATION_PDF=”application/pfd”; privatestaticfinalStringAPPLICATION_WORD=”application/msword”; privatestaticfinalStringAPPLICATION_EXCEL=”application/vnd.ms-excel;charset=utf-8″; @RequestMapping(value=”/download”,method=RequestMethod.GET,produces=APPLICATION_PDF) @ResponseBodypublicResourcedownload(HttpServletRequestreq,HttpServletResponseresp) { StringfileName=req.getParameter(“file”
下一篇:没有了
相关文章: