diff --git a/src/main/java/com/jingcheng/cms/controller/ArticleController.java b/src/main/java/com/jingcheng/cms/controller/ArticleController.java index d6f3af9..aee5ce8 100644 --- a/src/main/java/com/jingcheng/cms/controller/ArticleController.java +++ b/src/main/java/com/jingcheng/cms/controller/ArticleController.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.jingcheng.cms.model.Category; import com.jingcheng.cms.service.ArticleSerive; import com.jingcheng.cms.util.AjaxResult; +import com.jingcheng.cms.util.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestBody; @@ -13,6 +14,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.IOException; +import java.util.Date; import java.util.List; @RestController @@ -107,6 +109,11 @@ public class ArticleController { } //文件名称 String realFileName = file.getOriginalFilename(); + //文件前缀 + String fileName = realFileName.substring(0,realFileName.indexOf(".")) + DateUtils.date().getTime(); + //文件后缀 + String suffix = realFileName.substring(realFileName.lastIndexOf(".") + 1); + realFileName = fileName + "." + suffix; String path =localFilePath; //检查该路径对应的目录是否存在. 如果不存在则创建目录 File dir=new File(path); @@ -120,7 +127,7 @@ public class ArticleController { if (!(dest.exists())) { file.transferTo(dest); } - return filePath; + return "http://localhost:8888/upload/" + realFileName; } /** diff --git a/src/main/resources/application-production.yml b/src/main/resources/application-production.yml index cd9c28a..e24b785 100644 --- a/src/main/resources/application-production.yml +++ b/src/main/resources/application-production.yml @@ -59,7 +59,7 @@ upload: export: path: /tmp/export/ -localFilePath: D:/documentManager/upload +localFilePath: D:/documentManager/upload/ wx: BASE_URI: https://api.weixin.qq.com