


spring.mvc.static-path-pattern=/images/**

spring.web.resources.static-locations=classpath:/css



@PostMapping("upload")public String up(String nickname, MultipartFile photo, HttpServletRequest request) throws IOException {System.out.println(nickname);// 获取图片的原始名称System.out.println(photo.getOriginalFilename());// 获取文件类型System.out.println(photo.getContentType());System.out.println(System.getProperty("user.dir"));// 获取web服务器运行的目录String path = request.getServletContext().getRealPath("/upload/");System.out.println(path);saveFile(photo,path);return "上传成功!";}// 保存文件到web服务器public void saveFile(MultipartFile photo,String path) throws IOException{// 判断存储的目录是否存在,不存在则创建File dir = new File(path);if(!dir.exists()){// 创建目录dir.mkdir();}File file = new File(path+photo.getOriginalFilename());photo.transferTo(file);}


浏览器访问刚上传到web服务器的文件

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号