配置文件配置存放路徑app
upload-path=D:/upimages/
表單頁面編輯器
layedit.set({ uploadImage: { url: '/manage/upload' //接口url ,type: 'post' //默認post } }); var editIndex = layedit.build('content'); //創建編輯器
上傳actionide
@RequestMapping("upload") @ResponseBody public String upload(Model model,@RequestParam MultipartFile file) throws Exception { String picName = saveUplaodFile(uploadPath,file); String url="/upload/" + picName; String src=url; return "{\n" + " \"code\": 0,\n" + " \"msg\": \"\",\n" + " \"data\": {\n" + " \"src\": \""+src +"\"\n" + " }\n" + "}"; }
定義靜態文件訪問路徑,此處意思是http://****:8080/upload/ 映射到uploadPath目錄post
固然也能夠經過application.properties(yml)配置,自行baiduui
@Configuration public class InterceptorConfig implements WebMvcConfigurer { @Value("${upload-path}") private String uploadPath; @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/upload/**").addResourceLocations("file:"+uploadPath+""); }
效果以下url