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); }