diff --git a/src/main/java/com/fjy/spring/controller/DownLoadController.java b/src/main/java/com/fjy/spring/controller/DownLoadController.java index 18945ae..4b00b5e 100644 --- a/src/main/java/com/fjy/spring/controller/DownLoadController.java +++ b/src/main/java/com/fjy/spring/controller/DownLoadController.java @@ -21,10 +21,10 @@ public class DownLoadController { @Autowired private FileService fileService; - @GetMapping("/download") + /*@GetMapping("/download") public String toDownloadPage(){ - return "download"; - } + return "download/dodownload"; + }*/ @GetMapping("/download/findall") @ResponseBody @@ -37,7 +37,7 @@ public class DownLoadController { } @RequestMapping("/download/dodownload") - public String download(@RequestParam String fileName , HttpServletRequest request, HttpServletResponse response){ + public String download(@RequestParam Integer fileId , HttpServletRequest request, HttpServletResponse response){ response.setContentType("text/html;charset=utf-8"); try { @@ -49,19 +49,20 @@ public class DownLoadController { java.io.BufferedOutputStream bos = null; TbFile file = new TbFile(); - file.setColfilename(fileName); - - TbFile tbFile = fileService.findFile(file); + file.setColfileid(fileId); + TbFile tbFile = fileService.findFileById(file); + //TbFile tbFile = fileService.findFile(file); System.out.println(tbFile.getColfilepath()); String ctxPath = tbFile.getColfilepath(); - String downLoadPath = ctxPath + fileName; + String downLoadPath = ctxPath; + //String downLoadPath = ctxPath + tbFile.getColfilename(); System.out.println(downLoadPath); try { long fileLength = new File(downLoadPath).length(); response.setContentType("application/x-msdownload;"); - response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1")); + response.setHeader("Content-disposition", "attachment; filename=" + new String(tbFile.getColfilename().getBytes("utf-8"), "ISO8859-1")); response.setHeader("Content-Length", String.valueOf(fileLength)); bis = new BufferedInputStream(new FileInputStream(downLoadPath)); bos = new BufferedOutputStream(response.getOutputStream()); diff --git a/src/main/java/com/fjy/spring/controller/NavController.java b/src/main/java/com/fjy/spring/controller/NavController.java index 4f7c77e..9a37b36 100644 --- a/src/main/java/com/fjy/spring/controller/NavController.java +++ b/src/main/java/com/fjy/spring/controller/NavController.java @@ -14,4 +14,9 @@ public class NavController { public String toTestPage(){ return "/dist/thymeleafTest"; } + + @GetMapping(value = {"axiosTest"}) + public String toTestAxiosPage(){ + return "/dist/axiosTest"; + } } diff --git a/src/main/java/com/fjy/spring/controller/UpLoadController.java b/src/main/java/com/fjy/spring/controller/UpLoadController.java index 2423096..de99396 100644 --- a/src/main/java/com/fjy/spring/controller/UpLoadController.java +++ b/src/main/java/com/fjy/spring/controller/UpLoadController.java @@ -60,7 +60,8 @@ public class UpLoadController { @RequestMapping(value = "/oneUpload") public String oneUpload(@RequestParam("imageFile") MultipartFile imageFile, HttpServletRequest request) { - String uploadUrl = request.getSession().getServletContext().getRealPath("/") + "upload/"; + //String uploadUrl = request.getSession().getServletContext().getRealPath("/") + "upload/"; + String uploadUrl = serverProperties.getFilePath()+ "upload/"; String filename = imageFile.getOriginalFilename(); File dir = new File(uploadUrl); if (!dir.exists()) {//判断目录是否存在,否则自动创建 @@ -116,13 +117,13 @@ public class UpLoadController { * @return */ @RequestMapping("/moreUpload") - public String moreUpload(HttpServletRequest request) { + public void moreUpload(HttpServletRequest request) { MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request; Map files = multipartHttpServletRequest.getFileMap(); - String uploadUrl = request.getSession().getServletContext().getRealPath("/") + "upload/"; - + //String uploadUrl = request.getSession().getServletContext().getRealPath("/") + "upload/"; + String uploadUrl = serverProperties.getFilePath()+ "upload/"; File dir = new File(uploadUrl); if (!dir.exists()) { @@ -132,13 +133,17 @@ public class UpLoadController { List fileList = new ArrayList(); for (MultipartFile file : files.values()) { - File targetFile = new File(uploadUrl + file.getOriginalFilename()); + String filename = file.getOriginalFilename(); + File targetFile = new File(uploadUrl + filename); + System.out.println("文件上传到: " + uploadUrl + filename); + System.out.println("文件大小: " + new FormatFileSizeUtil().GetFileSize(file.getSize())); + System.out.println("文件名: " + filename); TbFile tbFile = new TbFile(); tbFile.setColfilesize(new FormatFileSizeUtil().GetFileSize(file.getSize())); - tbFile.setColfilename(file.getName()); - tbFile.setColfilepath(uploadUrl + file.getName()); + tbFile.setColfilename(filename); + tbFile.setColfilepath(uploadUrl + filename); tbFile.setColip(request.getRemoteAddr()); if (fileService.addFile(tbFile)) @@ -167,9 +172,5 @@ public class UpLoadController { } } - - request.setAttribute("files", fileList); - - return "moreUploadResult"; } } diff --git a/src/main/java/com/fjy/spring/properties/ServerProperties.java b/src/main/java/com/fjy/spring/properties/ServerProperties.java index d404495..61e8c13 100644 --- a/src/main/java/com/fjy/spring/properties/ServerProperties.java +++ b/src/main/java/com/fjy/spring/properties/ServerProperties.java @@ -7,6 +7,15 @@ import org.springframework.stereotype.Component; @ConfigurationProperties(prefix = "serverproperties") public class ServerProperties { private String portNum; + private String filePath; + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } public String getPortNum() { return portNum; diff --git a/src/main/java/com/fjy/spring/service/FileService.java b/src/main/java/com/fjy/spring/service/FileService.java index 424e0e1..0105a28 100644 --- a/src/main/java/com/fjy/spring/service/FileService.java +++ b/src/main/java/com/fjy/spring/service/FileService.java @@ -30,6 +30,10 @@ public class FileService { return tbFileRepository.findAll(); } + public TbFile findFileById(TbFile tbFile){ + return tbFileRepository.findById(tbFile.getColfileid()).get(); + } + } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index dd6e36f..03239bf 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -5,6 +5,7 @@ server: port: 8080 serverproperties: port_num: 8080 + filePath: F:\JAVA Workspace\Temp\ spring: thymeleaf: prefix: classpath:/templates/ diff --git a/src/main/resources/static/js/homePage.js b/src/main/resources/static/js/homePage.js index a7ccf3e..7141345 100644 --- a/src/main/resources/static/js/homePage.js +++ b/src/main/resources/static/js/homePage.js @@ -1,3 +1,11 @@ +axios.get('http://localhost:8080/cms/download/findall') + .then(function (response) { + console.log(response); + resolve(response.data); + }) + .catch(function (error) { + console.log(error); + }); var Main = { data() { return { @@ -10,44 +18,42 @@ var Main = { name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100' }], - tableData3: [{ - date: '2016-05-03', - name: '王小虎', - address: '上海市普陀区金沙江路 1518 弄' - }, { - date: '2016-05-02', - name: '王小虎', - address: '上海市普陀区金沙江路 1518 弄' - }, { - date: '2016-05-04', - name: '王小虎', - address: '上海市普陀区金沙江路 1518 弄' - }, { - date: '2016-05-01', - name: '王小虎', - address: '上海市普陀区金沙江路 1518 弄' - }, { - date: '2016-05-08', - name: '王小虎', - address: '上海市普陀区金沙江路 1518 弄' - }, { - date: '2016-05-06', - name: '王小虎', - address: '上海市普陀区金沙江路 1518 弄' - }, { - date: '2016-05-07', - name: '王小虎', - address: '上海市普陀区金沙江路 1518 弄' - }] + DownloadList: [ + { + colfileid: 9, + coluserid: 0, + colip: '0:0:0:0:0:0:0:1', + colrealname: '234234', + colfilename: '10K.jpg', + colfilesize: '21.78KB', + colfilepath: 'C:\\Users\\11860\\AppData\\Local\\Temp\\tomcat-docbase.8051654935022807536.8080\\upload/10K.jpg' + }, + { + colfileid: 15, + coluserid: 0, + colip: '0:0:0:0:0:0:0:1', + colrealname: null, + colfilename: '10K.jpg', + colfilesize: '21.78KB', + colfilepath: 'F:\\JAVA Workspace\\Temp\\upload/10K.jpg' + } + ] }; }, methods: { + handleClick(row) { + console.log(row.colfileid); + }, submitUpload() { this.$refs.upload.submit(); }, handleRemove(file, fileList) { console.log(file, fileList); }, + handleDownload(row){ + /*var url = window.location.protocol+"://"+window.location.host+":"+window.location.port+"/"*/ + window.open("http://localhost:8080/cms/download/dodownload?fileId="+row.colfileid); + }, handlePreview(file) { console.log(file); }, diff --git a/src/main/resources/templates/home/home.html b/src/main/resources/templates/home/home.html index 69b4d75..5f1ac12 100644 --- a/src/main/resources/templates/home/home.html +++ b/src/main/resources/templates/home/home.html @@ -5,6 +5,7 @@
+
@@ -14,7 +15,7 @@
- 选取文件 @@ -28,16 +29,17 @@
- - + + + - + - +