Profile configuration storage path
upload-path=D:/upimages/
Form page
layedit.set ({ uploadImage: { URL: '/ Manage / Upload' // Interface URL , type: 'POST' // default POST } }); var EditIndex = layedit.build ( 'Content'); // create an edited device
Upload action
@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" + "}"; }
Define a static file access path, where meaning is http: // ****: 8080 / upload / mapped to directory uploadPath
Also be implemented by application.properties (yml) configuration, self baidu
@Configuration public class InterceptorConfig implements WebMvcConfigurer { @Value("${upload-path}") private String uploadPath; @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/upload/**").addResourceLocations("file:"+uploadPath+""); }
Results are as follows