zoukankan      html  css  js  c++  java
  • 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 "{
    " +
                    "  "code": 0,
    " +
                    "  "msg": "",
    " +
                    "  "data": {
    " +
                    "    "src": ""+src +""
    " +
                    "  }
    " +
                    "}";
        }

    定义静态文件访问路径,此处意思是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+"");
        }

    效果如下

     

  • 相关阅读:
    总结
    总结
    总结
    总结
    合作成功案例
    本周作业
    上周作业
    本周总结
    本周作业
    分答
  • 原文地址:https://www.cnblogs.com/Guroer/p/11135913.html
Copyright © 2011-2022 走看看