@ResponseBody
@RequestMapping("/upload")
public Map<String, String> uploadaaa(MultipartFile file,HttpServletRequest request,HttpServletResponse response) throws IllegalStateException, IOException{
//String path = request.getSession().getServletContext().getRealPath("upload");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 HH:mm:ss
String date = df.format(new Date());// new Date()为获取当前系统时间,也可使用当前时间戳
String path = "C:/var/uploaded_files/"+date+"/";
UUID uuid=UUID.randomUUID();
String originalFilename = file.getOriginalFilename();
// String fileName = uuid.toString() + originalFilename;
String extendName = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
String fileName = uuid.toString() + extendName;
File dir = new File(path, fileName);
F
基于springboot 的上传(把图片存到服务器,把获取到的图片的地址存到数据库中)
最新推荐文章于 2024-06-28 17:01:04 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)