700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Spring Boot配置静态资源实现文件上传查看

Spring Boot配置静态资源实现文件上传查看

时间:2021-08-06 15:07:17

相关推荐

Spring Boot配置静态资源实现文件上传查看

spring.mvc.static-path-pattern

代表的含义是我们应该以什么样的路径来访问静态资源,换句话说,只有静态资源满足什么样的匹配条件,Spring Boot才会处理静态资源请求。

spring.resources.static-locations

用于告诉Spring Boot应该在何处查找静态资源文件,这是一个列表性的配置,查找文件时会依赖于配置的先后顺序依次进行。

spring:application:name: testservlet:multipart:max-file-size: 500MBmax-request-size: 500MBmvc:static-path-pattern: /material/**resources:static-locations: file:/opt/oa/enclosure/dispatch,file:/home/versioncn:chinaunicom:dispatchEnclosurePath: /opt/oa/enclosure/dispatchmaterialLink: http://10.163.76.160:9010/form/material/

配置以上属性,然后将一个图片(例如:1.jpg)和文档(例如:1.doc)放置到服务器/opt/oa/enclosure/dispatch或/home/version目录下,通过项目名http://10.163.76.160:9010/form/material/1.jpg进行在线打开图片,通过项目名http://10.163.76.160:9010/form/material/1.doc进行在线下载文档。

如果被拦截器拦截访问失败情况下选用

@Configurationpublic class LoggerWebAppConfig extends WebMvcConfigurationSupport {@Autowiredprivate LoggerInterceptor interceptor;@Overridepublic void addInterceptors(InterceptorRegistry registry) {// 拦截url配置//registry.addInterceptor(interceptor).addPathPatterns("/**");// 排除url配置registry.addInterceptor(interceptor).excludePathPatterns("/**/get**");}@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/material/**").addResourceLocations("file:/D://enclosure/img/","file:/D://enclosure/app/");super.addResourceHandlers(registry);}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。