去除后台下载文件中包含的bak备份目录

This commit is contained in:
F嘉阳
2018-02-27 12:45:05 +08:00
parent 20da1575f0
commit 287526a6e7
5 changed files with 44 additions and 49 deletions

View File

@@ -42,31 +42,31 @@ public class DownLoadController {
return "download/dodownload"; return "download/dodownload";
}*/ }*/
@GetMapping("/download/findall") @GetMapping("/home/admin/download/findall")
@ResponseBody @ResponseBody
public List<TbFile> toDownloadAll(){ public List<TbFile> toDownloadAll() {
List<TbFile> files = fileService.findAllFile();//此处做空指针判断并抛出错误 List<TbFile> files = fileService.findAllFile();//此处做空指针判断并抛出错误
if (files!=null) if (files != null)
return files; return files;
new UserException(ResultEnum.EMPTY_DATA); new UserException(ResultEnum.EMPTY_DATA);
return null; return null;
} }
@GetMapping("/download/findone") @GetMapping("/home/download/findone")
@ResponseBody @ResponseBody
public List<TbFile> toDownloadOne(){ public List<TbFile> toDownloadOne() {
TbUser user = (TbUser)request.getSession().getAttribute(USER_SESSION_KEY); TbUser user = (TbUser) request.getSession().getAttribute(USER_SESSION_KEY);
//log.info(user.toString()); //log.info(user.toString());
List<TbFile> files = fileService.findByColuserid(user.getColuserid()); List<TbFile> files = fileService.findByColuserid(user.getColuserid());
//此处做空指针判断并抛出错误 //此处做空指针判断并抛出错误
if (files!=null) if (files != null)
return files; return files;
new UserException(ResultEnum.EMPTY_DATA); new UserException(ResultEnum.EMPTY_DATA);
return null; return null;
} }
@RequestMapping("/download/dodownload") @RequestMapping("/home/download/dodownload")
public String download(@RequestParam Integer fileId , HttpServletRequest request, HttpServletResponse response){ public String download(@RequestParam Integer fileId, HttpServletRequest request, HttpServletResponse response) {
response.setContentType("text/html;charset=utf-8"); response.setContentType("text/html;charset=utf-8");
try { try {
@@ -124,16 +124,17 @@ public class DownLoadController {
/** /**
* 传入课程名和文件夹名称,打包下载目录下所有文件 * 传入课程名和文件夹名称,打包下载目录下所有文件
*
* @param courseName * @param courseName
* @param folder * @param folder
* @param response * @param response
*/ */
@GetMapping("/download/downloadzip") @GetMapping("/home/admin/download/downloadzip")
public void batDownload(@RequestParam(value = "courseName") String courseName, public void batDownload(@RequestParam(value = "courseName") String courseName,
@RequestParam(value = "Folder")String folder, HttpServletResponse response){ @RequestParam(value = "Folder") String folder, HttpServletResponse response) {
//获取文件夹名称 //获取文件夹名称
String paths = serverProperties.getFilePath()+ "upload/"+courseName+"/"+folder; String paths = serverProperties.getFilePath() + "upload/" + courseName + "/" + folder;
String zipPath = serverProperties.getFilePath()+"zip/"; String zipPath = serverProperties.getFilePath() + "zip/";
File dir = new File(zipPath); File dir = new File(zipPath);
if (!dir.exists()) { if (!dir.exists()) {
@@ -141,12 +142,12 @@ public class DownLoadController {
} }
List<String> pathList = new ArrayList<String>(); List<String> pathList = new ArrayList<String>();
pathList=getFileString(paths); pathList = getFileString(paths);
//需要压缩的文件--包括文件地址和文件名 //需要压缩的文件--包括文件地址和文件名
String []path =(String[])pathList.toArray(new String[0]); String[] path = (String[]) pathList.toArray(new String[0]);
// 要生成的压缩文件地址和文件名称 // 要生成的压缩文件地址和文件名称
String zipFileName=courseName+folder+".zip"; String zipFileName = courseName + folder + ".zip";
String desPath = zipPath+"\\"+zipFileName; String desPath = zipPath + "\\" + zipFileName;
//System.out.println("打包文件存储地址:"+desPath); //System.out.println("打包文件存储地址:"+desPath);
File zipFile = new File(desPath); File zipFile = new File(desPath);
@@ -156,24 +157,25 @@ public class DownLoadController {
try { try {
//构造最终压缩包的输出流 //构造最终压缩包的输出流
zipStream = new ZipOutputStream(new FileOutputStream(zipFile)); zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
for(int i =0;i<path.length;i++){ for (int i = 0; i < path.length; i++) {
File file = new File(path[i]); File file = new File(path[i]);
//将需要压缩的文件格式化为输入流 //将需要压缩的文件格式化为输入流
zipSource = new FileInputStream(file); if (!file.isDirectory()){
//压缩条目不是具体独立的文件,而是压缩包文件列表中的列表项,称为条目,就像索引一样 zipSource = new FileInputStream(file);
ZipEntry zipEntry = new ZipEntry(file.getName()); //压缩条目不是具体独立的文件,而是压缩包文件列表中的列表项,称为条目,就像索引一样
//定位该压缩条目位置,开始写入文件到压缩包中 ZipEntry zipEntry = new ZipEntry(file.getName());
//定位该压缩条目位置,开始写入文件到压缩包中
zipStream.putNextEntry(zipEntry); zipStream.putNextEntry(zipEntry);
//输入缓冲流 //输入缓冲流
bufferStream = new BufferedInputStream(zipSource, 1024 * 10); bufferStream = new BufferedInputStream(zipSource, 1024 * 10);
int read = 0; int read = 0;
//创建读写缓冲区 //创建读写缓冲区
byte[] buf = new byte[1024 * 10]; byte[] buf = new byte[1024 * 10];
while((read = bufferStream.read(buf, 0, 1024 * 10)) != -1) while ((read = bufferStream.read(buf, 0, 1024 * 10)) != -1) {
{ zipStream.write(buf, 0, read);
zipStream.write(buf, 0, read); }
} }
} }
@@ -182,9 +184,9 @@ public class DownLoadController {
} finally { } finally {
//关闭流 //关闭流
try { try {
if(null != bufferStream) bufferStream.close(); if (null != bufferStream) bufferStream.close();
if(null != zipStream) zipStream.close(); if (null != zipStream) zipStream.close();
if(null != zipSource) zipSource.close(); if (null != zipSource) zipSource.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -226,6 +228,7 @@ public class DownLoadController {
/** /**
* 获取目录下所有文件的路径 * 获取目录下所有文件的路径
*
* @param fileDir * @param fileDir
* @return * @return
*/ */
@@ -235,7 +238,7 @@ public class DownLoadController {
File[] files = file.listFiles();// 获取目录下的所有文件或文件夹 File[] files = file.listFiles();// 获取目录下的所有文件或文件夹
List<String> path = new ArrayList<String>(); List<String> path = new ArrayList<String>();
List<String> name = new ArrayList<String>(); List<String> name = new ArrayList<String>();
int i = 0,j=0; int i = 0, j = 0;
if (files == null) {// 如果目录为空,直接退出 if (files == null) {// 如果目录为空,直接退出
path.add("空目录"); path.add("空目录");
return path; return path;

View File

@@ -6,7 +6,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/*@Configuration*/ @Configuration
public class WebAppConfig implements WebMvcConfigurer { public class WebAppConfig implements WebMvcConfigurer {
/** /**

View File

@@ -62,7 +62,7 @@ var Main = {
}, },
methods: { methods: {
uploadURL(row) { uploadURL(row) {
return getRootPath_web()+"/moreUpload?rename=false"; return getRootPath_web()+"/home/moreUpload?rename=false";
}, },
submitUpload() { submitUpload() {
this.$refs.upload.submit(); this.$refs.upload.submit();

View File

@@ -200,7 +200,7 @@ var Main = {
methods: { methods: {
getFileList(){ getFileList(){
let that = this; let that = this;
axios.get(getRootPath_web()+'/download/findone') axios.get(getRootPath_web()+'/home/download/findone')
.then(function (response) { .then(function (response) {
//console.log(response.data); //console.log(response.data);
that.DownloadList = response.data; that.DownloadList = response.data;
@@ -230,7 +230,7 @@ var Main = {
}); });
}, },
uploadURL(row) { uploadURL(row) {
return getRootPath_web()+"/moreUpload?courseName=" + row.coursename + "&folder=" + row.workfolder+"&rename=true"; return getRootPath_web()+"/home/moreUpload?courseName=" + row.coursename + "&folder=" + row.workfolder+"&rename=true";
}, },
limitTime(row) { limitTime(row) {
return DateDiff(row.worktime.replace(/([^\s]+)\s.*/, "$1"), cur); return DateDiff(row.worktime.replace(/([^\s]+)\s.*/, "$1"), cur);
@@ -300,7 +300,7 @@ var Main = {
}, },
handleDownload(row) { handleDownload(row) {
/*var url = window.location.protocol+"://"+window.location.host+":"+window.location.port+"/"*/ /*var url = window.location.protocol+"://"+window.location.host+":"+window.location.port+"/"*/
window.open(getRootPath_web()+"/download/dodownload?fileId=" + row.colfileid); window.open(getRootPath_web()+"/home/download/dodownload?fileId=" + row.colfileid);
}, },
handleDelete(row) { handleDelete(row) {
let that = this; let that = this;

View File

@@ -51,14 +51,6 @@ var Main = {
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);
}); });
axios.get(getRootPath_web()+'/home/findallvhomework')
.then(function (response) {
console.log(response.data);
that.homeworkData = response.data;
})
.catch(function (error) {
console.log(error);
});
}) })
}, },
methods: { methods: {
@@ -111,7 +103,7 @@ var Main = {
}, },
handleDownload(row) { handleDownload(row) {
/*var url = window.location.protocol+"://"+window.location.host+":"+window.location.port+"/"*/ /*var url = window.location.protocol+"://"+window.location.host+":"+window.location.port+"/"*/
window.open(getRootPath_web()+"/download/downloadzip?courseName=" window.open(getRootPath_web()+"/home/admin/download/downloadzip?courseName="
+ row.courseName+"&Folder="+row.folder); + row.courseName+"&Folder="+row.folder);
}, },
handleSelect(key, keyPath) { handleSelect(key, keyPath) {