From 080bf5737810debff6e2962d0b61bc807c072dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=E5=98=89=E9=98=B3?= Date: Sat, 23 Jun 2018 13:23:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UploadController.java | 21 ++- src/main/resources/static/js/upload.js | 27 ++++ .../templates/dist/thymeleaf/common_foot.html | 6 + .../templates/dist/thymeleaf/common_head.html | 20 +++ .../templates/dist/thymeleaf/footer.html | 9 ++ .../templates/dist/thymeleaf/layout.html | 122 ++++++++++++++++++ src/main/resources/templates/home/upload.html | 19 +++ src/main/resources/templates/upload/add.html | 10 ++ 8 files changed, 227 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/static/js/upload.js create mode 100644 src/main/resources/templates/dist/thymeleaf/common_foot.html create mode 100644 src/main/resources/templates/dist/thymeleaf/common_head.html create mode 100644 src/main/resources/templates/dist/thymeleaf/footer.html create mode 100644 src/main/resources/templates/dist/thymeleaf/layout.html create mode 100644 src/main/resources/templates/home/upload.html create mode 100644 src/main/resources/templates/upload/add.html diff --git a/src/main/java/top/fjy8018/fileupload/controller/UploadController.java b/src/main/java/top/fjy8018/fileupload/controller/UploadController.java index 2b149a8..079233d 100644 --- a/src/main/java/top/fjy8018/fileupload/controller/UploadController.java +++ b/src/main/java/top/fjy8018/fileupload/controller/UploadController.java @@ -1,7 +1,9 @@ package top.fjy8018.fileupload.controller; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -23,6 +25,7 @@ import java.util.Map; * @author F嘉阳 * @date 2018-06-23 09:16 */ +@Slf4j @Controller @RequestMapping("/upload") public class UploadController { @@ -33,25 +36,30 @@ public class UploadController { @Autowired private ServerPropertiesConfig serverPropertiesConfig; + @GetMapping("") + public String toUploadPage(){ + return "home/upload.html"; + } + @PostMapping("/add") - public String moreUpload(HttpServletRequest request, - @RequestParam(value = "fileName") String fileName) { + public void moreUpload(HttpServletRequest request) { MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request; Map files = multipartHttpServletRequest.getFileMap(); - User user = (User)request.getSession().getAttribute(GlobalConstant.USER_SESSION_KEY); + //User user = (User)request.getSession().getAttribute(GlobalConstant.USER_SESSION_KEY); EsFileInfo fileInfo = new EsFileInfo(); for (MultipartFile file : files.values()) { - String pathname = serverPropertiesConfig.getFilePath()+fileName; + String pathname = serverPropertiesConfig.getFilePath()+file.getOriginalFilename(); File targetFile = new File(pathname); - fileInfo.setFileName(fileName); + fileInfo.setFileName(file.getOriginalFilename()); fileInfo.setFilePath(pathname); fileInfo.setFileSize(FormatFileSizeUtil.GetFileSize(file.getSize())); - fileInfo.setUserId(user.getId()); + fileInfo.setUserId("1529723171835369380"); + log.info("【文件上传信息】fileinfo{},PostFile:{}",fileInfo.toString(),file.getOriginalFilename()); // 写入ES fileService.saveFile(fileInfo); @@ -61,6 +69,5 @@ public class UploadController { e.printStackTrace(); } } - return null; } } diff --git a/src/main/resources/static/js/upload.js b/src/main/resources/static/js/upload.js new file mode 100644 index 0000000..2b79b42 --- /dev/null +++ b/src/main/resources/static/js/upload.js @@ -0,0 +1,27 @@ +var Main = { + data() { + return { + fileList: [ + { + name: 'food.jpeg', + url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100' + }, { + name: 'food2.jpeg', + url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100' + }] + }; + }, + methods: { + submitUpload() { + this.$refs.upload.submit(); + }, + handleRemove(file, fileList) { + console.log(file, fileList); + }, + handlePreview(file) { + console.log(file); + } + } +} +var Ctor = Vue.extend(Main) +new Ctor().$mount('#app') \ No newline at end of file diff --git a/src/main/resources/templates/dist/thymeleaf/common_foot.html b/src/main/resources/templates/dist/thymeleaf/common_foot.html new file mode 100644 index 0000000..77cbbc9 --- /dev/null +++ b/src/main/resources/templates/dist/thymeleaf/common_foot.html @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/dist/thymeleaf/common_head.html b/src/main/resources/templates/dist/thymeleaf/common_head.html new file mode 100644 index 0000000..ffe8934 --- /dev/null +++ b/src/main/resources/templates/dist/thymeleaf/common_head.html @@ -0,0 +1,20 @@ + + + + + + + + + + + +
+ + + + + +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/dist/thymeleaf/footer.html b/src/main/resources/templates/dist/thymeleaf/footer.html new file mode 100644 index 0000000..a62d5f1 --- /dev/null +++ b/src/main/resources/templates/dist/thymeleaf/footer.html @@ -0,0 +1,9 @@ + + + +
+ © 2016 xxx +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/dist/thymeleaf/layout.html b/src/main/resources/templates/dist/thymeleaf/layout.html new file mode 100644 index 0000000..b49853c --- /dev/null +++ b/src/main/resources/templates/dist/thymeleaf/layout.html @@ -0,0 +1,122 @@ + + + + + + 首页 + 个人中心 + 关于 + 意见反馈 + 登出 + + + + + + +
默认颜色
+ + + + + + 选项1 + 选项2 + + + 选项3 + + + + 选项1 + + + + + 导航二 + + + + 导航三 + + +
+
+
+ + +
+ + 用户名
+ +
+
+ 首页 +
+ 个人中心 +
+ 关于 +
+ 意见反馈 +
+
+ + +
+ 管理员
+ 管理员号 +
+
+ 后台主页 +
+ 课程管理 +
+ 作业管理 +
+ 用户管理 +
+
+ + +
+ 作业提交倒计时 + + +
+
+ + + + + + + + + +
+
+ + +
+ 公告 +
+
+ {{notice.noticeContent + notice.issueTime}} +
+
+ + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/home/upload.html b/src/main/resources/templates/home/upload.html new file mode 100644 index 0000000..b55f26f --- /dev/null +++ b/src/main/resources/templates/home/upload.html @@ -0,0 +1,19 @@ + + + + + +
+
+ + 选取文件 + 上传到服务器 +
只能上传jpg/png文件,且不超过100Mb
+
+
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/upload/add.html b/src/main/resources/templates/upload/add.html new file mode 100644 index 0000000..84f256e --- /dev/null +++ b/src/main/resources/templates/upload/add.html @@ -0,0 +1,10 @@ + + + + + 上传成功 + + + + + \ No newline at end of file