/**
* 下载文件,传入完成路径,先检查文件是否存在,如果存在就下载
* @param path
*/
downloadFileWithPath = function (path) {
$.ajax({
url: Hussar.ctxPath + '/checkFileExist',
type: 'get',
async: true,
data: {
path
},
success(res) {
if (res.code === 500) {
Hussar.valid(res.msg)
return
}
// 如果文件存在,那么就下载文件
window.location.href = '/downLoadFile?path=' + path
},
error() {
Hussar.valid('查询文件资源失败')
}
})
}
/**
* 检查文件是否存在
*
* @param path
* @return
*/
@RequestMapping("/checkFileExist")
@ResponseBody
public Map<String, Object> checkFileExist(String path) {
try {
File file = new File(path);
if (file.exists()) {
if (file.isDirectory()) {
return ReturnBodyUtil.returnError("下载所需的文件不存在");
} else {
return ReturnBodyUtil.returnSuccess(null);
}
} else {
return ReturnBodyUtil.returnError("下载所需的文件不存在");
}
} catch (Exception e) {
return ReturnBodyUtil.returnError("查询文件路径失败");
}
}