package cn.ksource.web.controller.file; import java.io.File; import java.io.IOException; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import cn.ksource.core.util.ConvertUtil; import cn.ksource.core.util.DownloadUtil; import cn.ksource.web.facade.file.FileFacade; /** * 文档管理控制器 * @author lixiang * @date 2016-07-12 */ @Controller @RequestMapping("/business/pages/file") public class FileController { @Resource(name="fileFacade") private FileFacade fileFacade; /** * 下载文件 */ @RequestMapping("downloadFile.html") public void downloadFile(HttpServletRequest request,HttpServletResponse response) { String fileId = request.getParameter("fileId"); Map fileMsg = fileFacade.queryFileMsg(fileId); if(null!=fileMsg && fileMsg.size()>0) { String fileName = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_NAME")); String filePath = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_PATH")); String basePath = request.getSession().getServletContext().getRealPath(""); System.out.println("path------------------------>"+basePath+filePath); File file = new File(basePath+filePath); try { DownloadUtil.download(response, file, fileName, false); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /** * 下载DSL文件 */ @RequestMapping("downloadDslFile.html") public void downloadDslFile(HttpServletRequest request,HttpServletResponse response) { String fileId = request.getParameter("fileId"); Map fileMsg = fileFacade.queryDslFileMsg(fileId); if(null!=fileMsg && fileMsg.size()>0) { String fileName = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_NAME")); String filePath = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_PATH")); String basePath = request.getSession().getServletContext().getRealPath(""); System.out.println("path------------------------>"+basePath+filePath); File file = new File(basePath+filePath); try { DownloadUtil.download(response, file, fileName, false); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }