From da26943ea5fb7f9f1a4e92b24cffa442a65de80a Mon Sep 17 00:00:00 2001 From: zxm <154040976@qq.com> Date: Tue, 9 Oct 2018 23:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=9B=BE=E7=89=87=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../len/controller/BlogAdminController.java | 24 ++++++++++++++++++- .../main/java/com/len/config/ShiroConfig.java | 1 + .../java/com/len/config/WebMvcConfig.java | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/len-blog/src/main/java/com/len/controller/BlogAdminController.java b/len-blog/src/main/java/com/len/controller/BlogAdminController.java index 3f23ee2..ae66901 100644 --- a/len-blog/src/main/java/com/len/controller/BlogAdminController.java +++ b/len-blog/src/main/java/com/len/controller/BlogAdminController.java @@ -4,8 +4,12 @@ import com.len.entity.BlogArticle; import com.len.service.BlogArticleService; import com.len.util.JsonUtil; import com.len.util.ReType; +import com.len.util.UploadUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; import tk.mybatis.mapper.entity.Condition; import javax.servlet.http.HttpServletRequest; @@ -27,6 +31,12 @@ public class BlogAdminController { @Autowired private BlogArticleService articleService; + @Value("${lenosp.imagePath}") + private String imagePath; + + @Autowired + private UploadUtil uploadUtil; + @GetMapping("/article/getList") public ReType getArticleList(BlogArticle article, Integer page, Integer limit) { return articleService.getList(article, page, limit); @@ -54,5 +64,17 @@ public class BlogAdminController { return json; } - + @PostMapping("/article/addImage") + public JsonUtil addImage(MultipartHttpServletRequest request) { + MultipartFile multipartFile = request.getFile("file"); + String path = uploadUtil.upload(multipartFile); + JsonUtil json = new JsonUtil(); + StringBuffer requestURL = request.getRequestURL(); + int serverPort = request.getServerPort(); + int i = requestURL.indexOf(String.valueOf(serverPort)); + String url= requestURL.substring(0,i); + json.setData(url+String.valueOf(serverPort)+"/img/"+path); + json.setFlag(true); + return json; + } } diff --git a/len-web/src/main/java/com/len/config/ShiroConfig.java b/len-web/src/main/java/com/len/config/ShiroConfig.java index 7e71e29..c0cabe1 100644 --- a/len-web/src/main/java/com/len/config/ShiroConfig.java +++ b/len-web/src/main/java/com/len/config/ShiroConfig.java @@ -138,6 +138,7 @@ public class ShiroConfig { filterMap.put("/login", "verCode,anon"); filterMap.put("/blogLogin", "verCode,anon"); filterMap.put("/getCode", "anon"); + filterMap.put("/img/**", "anon"); filterMap.put("/logout", "logout"); filterMap.put("/plugin/**", "anon"); filterMap.put("/user/**", "per"); diff --git a/len-web/src/main/java/com/len/config/WebMvcConfig.java b/len-web/src/main/java/com/len/config/WebMvcConfig.java index a09d041..3b7a744 100644 --- a/len-web/src/main/java/com/len/config/WebMvcConfig.java +++ b/len-web/src/main/java/com/len/config/WebMvcConfig.java @@ -51,6 +51,7 @@ public class WebMvcConfig extends WebMvcConfigurationSupport { .addResourceLocations("classpath:/plugin/", "classpath:/static/"); registry.addResourceHandler("/ftl/**").addResourceLocations("classpath:/ftl/"); registry.addResourceHandler("/images/**").addResourceLocations("file:" + imagePath); + registry.addResourceHandler("/img/**").addResourceLocations("file:" + imagePath); registry.addResourceHandler("/file/**").addResourceLocations("file:" + imagePath); super.addResourceHandlers(registry); }