zhangshuting_branch
2593162056@qq.com 8 months ago
parent a24b27043f
commit 9bc35e6eed

@ -2,9 +2,6 @@ package com.controller;
import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
@ -43,33 +40,29 @@ public class FileController{
public R upload(@RequestParam("file") MultipartFile file, String type,HttpServletRequest request) throws Exception {
if (file.isEmpty()) {
throw new EIException("上传文件不能为空");
}String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
String path = URLDecoder.decode(request.getSession().getServletContext().getRealPath("/upload"),"UTF-8");
File dest = new File(path);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}String path2 = path.replace("target\\jspm0c59i\\upload", "src\\main\\webapp\\upload\\");
File upload2 = new File(path2);
if (!upload2.exists()) {
upload2.mkdirs();
}
String fileName = new Date().getTime() + "." + fileExt;
File dest1 = new File(dest.getAbsolutePath() + "/" + fileName);
File dest2 = new File(upload2.getAbsolutePath() + "/" + fileName);
file.transferTo(dest1);
Files.copy(dest1.toPath(), dest2.toPath(), StandardCopyOption.REPLACE_EXISTING);
String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
String fileName = new Date().getTime()+"."+fileExt;
File dest = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName);
file.transferTo(dest);
/**
* 使ideaeclipse
* "D:\\ssmpiv99\\src\\main\\webapp\\upload"upload
*
*/
//FileUtils.copyFile(dest, new File("D:\\ssmpiv99\\src\\main\\webapp\\upload"+"/"+fileName)); /**修改了路径以后请将该行最前面的//注释去掉**/
if(StringUtils.isNotBlank(type) && type.equals("1")) {
ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
if(configEntity==null) {
configEntity = new ConfigEntity();
configEntity.setName("faceFile");
configEntity.setValue(fileName);
}else {
} else {
configEntity.setValue(fileName);
}configService.insertOrUpdate(configEntity);
}return R.ok().put("file", fileName);
}
configService.insertOrUpdate(configEntity);
}
return R.ok().put("file", fileName);
}
/**

@ -28,7 +28,6 @@ import com.baomidou.mybatisplus.enums.IdType;
* @email
* @date 2023-02-21 09:46:06
*/
//
@TableName("wenjuandiaocha")
public class WenjuandiaochaEntity<T> implements Serializable {
private static final long serialVersionUID = 1L;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 170 KiB

Loading…
Cancel
Save