master
黄欣 5 years ago
parent 996eca9014
commit 4997a19b4b

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.jingcheng.cms.model.Category; import com.jingcheng.cms.model.Category;
import com.jingcheng.cms.service.ArticleSerive; import com.jingcheng.cms.service.ArticleSerive;
import com.jingcheng.cms.util.AjaxResult; 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.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -13,6 +14,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Date;
import java.util.List; import java.util.List;
@RestController @RestController
@ -107,6 +109,11 @@ public class ArticleController {
} }
//文件名称 //文件名称
String realFileName = file.getOriginalFilename(); 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; String path =localFilePath;
//检查该路径对应的目录是否存在. 如果不存在则创建目录 //检查该路径对应的目录是否存在. 如果不存在则创建目录
File dir=new File(path); File dir=new File(path);
@ -120,7 +127,7 @@ public class ArticleController {
if (!(dest.exists())) { if (!(dest.exists())) {
file.transferTo(dest); file.transferTo(dest);
} }
return filePath; return "http://localhost:8888/upload/" + realFileName;
} }
/** /**

@ -59,7 +59,7 @@ upload:
export: export:
path: /tmp/export/ path: /tmp/export/
localFilePath: D:/documentManager/upload localFilePath: D:/documentManager/upload/
wx: wx:
BASE_URI: https://api.weixin.qq.com BASE_URI: https://api.weixin.qq.com

Loading…
Cancel
Save