From de51cad5a54ad00ec7c6e3a125fe0d28a3d246b4 Mon Sep 17 00:00:00 2001 From: zhengzheng <18918765049@163.com> Date: Mon, 2 May 2022 14:28:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/wuzhen/ZtApplication.java | 19 +- .../controller/busi/ActiveInfoController.java | 78 ++++- .../com/wuzhen/web/core/config/WebConfig.java | 34 +++ zt-admin/src/main/resources/application.yml | 7 +- .../resources/templates/active/info/add.html | 281 ++++++++++++------ .../wuzhen/framework/config/ShiroConfig.java | 1 + .../com/wuzhen/system/domain/ActiveInfo.java | 6 +- 7 files changed, 325 insertions(+), 101 deletions(-) create mode 100644 zt-admin/src/main/java/com/wuzhen/web/core/config/WebConfig.java diff --git a/zt-admin/src/main/java/com/wuzhen/ZtApplication.java b/zt-admin/src/main/java/com/wuzhen/ZtApplication.java index 7412e8fed..f8f1d5ab8 100644 --- a/zt-admin/src/main/java/com/wuzhen/ZtApplication.java +++ b/zt-admin/src/main/java/com/wuzhen/ZtApplication.java @@ -1,8 +1,11 @@ package com.wuzhen; +import com.wuzhen.common.config.RuoYiConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * 启动程序 @@ -10,7 +13,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; * @author zhengzheng */ @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) -public class ZtApplication +public class ZtApplication implements WebMvcConfigurer { public static void main(String[] args) { @@ -27,4 +30,18 @@ public class ZtApplication " | | \\ / \\ / \n" + " ''-' `'-' `-..-' "); } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + /** + * 访问路径:http://localhost:93/facereport/static/captured/daping_report/captured_images/face/788001414206074880/2021/1/27/cj_142207194912440320.png + * "/facereport/static/captured/**" 为前端URL访问路径 + * "file:" + uploadPath 是本地磁盘映射 + */ + registry.addResourceHandler("/fp/**").addResourceLocations("file:" + RuoYiConfig.getProfile()+"/fp/"); + registry.addResourceHandler("/lp/**").addResourceLocations("file:" + RuoYiConfig.getLPUploadPath()+"/"); + System.out.println( RuoYiConfig.getLPUploadPath()+"/"); +// registry.addResourceHandler("/**").addResourceLocations("file:" + RuoYiConfig.getProfile()); + } + } \ No newline at end of file diff --git a/zt-admin/src/main/java/com/wuzhen/web/controller/busi/ActiveInfoController.java b/zt-admin/src/main/java/com/wuzhen/web/controller/busi/ActiveInfoController.java index a4d5cc160..2e792a8a0 100644 --- a/zt-admin/src/main/java/com/wuzhen/web/controller/busi/ActiveInfoController.java +++ b/zt-admin/src/main/java/com/wuzhen/web/controller/busi/ActiveInfoController.java @@ -1,5 +1,6 @@ package com.wuzhen.web.controller.busi; +import com.alibaba.fastjson.JSONObject; import com.wuzhen.common.annotation.Log; import com.wuzhen.common.config.RuoYiConfig; import com.wuzhen.common.core.controller.BaseController; @@ -19,7 +20,9 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.util.List; @@ -96,9 +99,10 @@ public class ActiveInfoController extends BaseController @ResponseBody public AjaxResult addSave(@Validated ActiveInfo activeInfo) { - MultipartFile file = activeInfo.getActivePic(); + MultipartFile[] files = activeInfo.getActivePic(); + MultipartFile file = files[0]; // 获取上传文件名 - String filename = file.getOriginalFilename(); + String filename = files[0].getOriginalFilename(); if (!"".equals(filename)){ // 定义上传文件保存路径 @@ -366,4 +370,74 @@ public class ActiveInfoController extends BaseController // roleService.checkRoleDataScope(roleId); // return toAjax(roleService.insertAuthUsers(roleId, userIds)); // } + + + + public static void uploadFile(byte[] file, String filePath, String fileName) throws Exception { + File targetFile = new File(filePath); + if (!targetFile.exists()) { + targetFile.mkdirs(); + } + FileOutputStream out = new FileOutputStream(filePath+"/"+ fileName); + out.write(file); + out.flush(); + out.close(); + } + + //处理文件上传 + @ResponseBody //返回json数据 + @RequestMapping(value = "upload", method = RequestMethod.POST) + public JSONObject uploadImg( @RequestPart("myFile") MultipartFile[] files) { + JSONObject jo = new JSONObject();//实例化json数据 + String fileNameArr[] =null; + if (files==null||files.length==0) { + jo.put("success", 0); + jo.put("fileName",new String[]{}); + }else { + fileNameArr=new String[files.length]; + } + for ( int i =0 ;i - + - - - + + + -
-
-
- -
- -
-
-
- -
- -
-
+
+ +
+ +
+ +
+
+
+ +
+ +
+
-
- -
- -
-
-
- -
- -
-
+
+ +
+ +
+
+
+ +
+ +
+
-
- -
- - - -
+
+ +
+ + -
+

+ + + +
-
- +
+
+ + + + + +
+
-
-
- - -
-
-
+
-
- +
+ -
-
- - -
-
-
+
+
+ + +
+
+
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
+
+ - -
- - - - - +
+
+ + +
+
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ + +
+ + + + + - - + + + $(function () { + $("#button").click(function () { + var form = new FormData(); + var files = document.getElementById("activePic").files; + if(files.length > 5) { + alert("上传图片不能超过5张!"); + return 0; + } + + $.each(files, function (i, file) { + form.append('myFile', file); }); + + $.ajax({ + url: ctx + "active/info/upload", + data: form, + cache: false, + async: false, + type: "POST", + dataType: 'json', + processData: false, + contentType: false, + success: function (data) { + if (data) { + alert(data); + var imgs = data.fileName; + $.each(imgs, function (i, path) { + + var id = "#showUserImg"+i; + alert(id+path); + $(id).attr("src", "/lp/"+path ); + }); + + + + + + + } else { + alert("失败"); + } + }, + error: function (er) { + alert(JSON.stringify(data)); + } + }); + + }); + + + }); + + + + + + + + + + + + + + + + + + diff --git a/zt-framework/src/main/java/com/wuzhen/framework/config/ShiroConfig.java b/zt-framework/src/main/java/com/wuzhen/framework/config/ShiroConfig.java index dbe7bbcf4..6801eedb9 100644 --- a/zt-framework/src/main/java/com/wuzhen/framework/config/ShiroConfig.java +++ b/zt-framework/src/main/java/com/wuzhen/framework/config/ShiroConfig.java @@ -281,6 +281,7 @@ public class ShiroConfig filterChainDefinitionMap.put("/html/**", "anon"); filterChainDefinitionMap.put("/css/**", "anon"); filterChainDefinitionMap.put("/docs/**", "anon"); + filterChainDefinitionMap.put("/lp/**", "anon"); filterChainDefinitionMap.put("/fonts/**", "anon"); filterChainDefinitionMap.put("/img/**", "anon"); filterChainDefinitionMap.put("/ajax/**", "anon"); diff --git a/zt-system/src/main/java/com/wuzhen/system/domain/ActiveInfo.java b/zt-system/src/main/java/com/wuzhen/system/domain/ActiveInfo.java index f630404ba..c1e64c7c2 100644 --- a/zt-system/src/main/java/com/wuzhen/system/domain/ActiveInfo.java +++ b/zt-system/src/main/java/com/wuzhen/system/domain/ActiveInfo.java @@ -59,7 +59,7 @@ public class ActiveInfo extends BaseEntity { /** * 活动图片 */ - private MultipartFile activePic; + private MultipartFile[] activePic; @@ -202,11 +202,11 @@ public class ActiveInfo extends BaseEntity { this.activeType = activeType; } - public MultipartFile getActivePic() { + public MultipartFile[] getActivePic() { return activePic; } - public void setActivePic(MultipartFile activePic) { + public void setActivePic(MultipartFile[] activePic) { this.activePic = activePic; }