springboot&layedit 上传文件,配置静态资源文件,存放磁盘其他目录

配置文件配置存放路径

upload-path=D:/upimages/

 

表单页面

       layedit.set({
            uploadImage: {
                url:  '/manage/upload' //接口url
                ,type: 'post' //默认post
            }
        });
        var editIndex =  layedit.build('content'); //建立编辑器

上传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" +
                "}";
    }

 

 

定义静态文件访问路径,此处意思是http://****:8080/upload/ 映射到uploadPath目录

当然也可以通过application.properties(yml)配置,自行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+"");
    }

 

效果如下

 

 

 

 

 

 

 

posted @ 2019-07-05 00:14  glory.xu  阅读(803)  评论(0编辑  收藏  举报