在 application.properties 追加
#file upload 访问路径file.staticAccessPath= /pic/**# 物理存储路径file.uploadRealPath= file:D:/pic/
创建一下配置类
@Configurationpublic class WebMvcConfig implements WebMvcConfigurer {@Value("${file.staticAccessPath}")private String staticAccessPath;//访问路径@Value("${file.uploadRealPath}")private String uploadRealPath;//上传路径@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler(staticAccessPath).addResourceLocations(uploadRealPath);}}
private String filePath ="d:/pic/";@RequestMapping("upFile")public ResponseResult upFile(MultipartFile file) throws IOException {if(null!=file && !file.isEmpty()){String oName = file.getOriginalFilename();String fileName= UUID.randomUUID()+oName.substring(oName.lastIndexOf("."));File upFile = new File(filePath, fileName);file.transferTo(upFile);return ResponseResult.ok("/pic/"+fileName);}return ResponseResult.fail(300,"上传失败,请选择上传文件");}
以上内容都是element-ui 官网复制
留言与评论(共有 0 条评论) “” |