静态文静映射配置

静态文静映射配置

方式一:把 excel 模板放到 web_ui 下,访问 http://localhost:8080/static/excel名称 即可下载

# 这里表示只有静态资源的访问路径为/static/**时,才会处理请求
spring.mvc.static-path-pattern=/static/**
#windows 环境
spring.resources.static-locations=file:C://web_ui/
#Linux 环境
spring.resources.static-locations=file:/home/gdop/web_ui/

  

 方式二:把 excel 模板放到 resource/static下,访问 http://localhost:8080/pub/excel名称 即可下载

package com.deallinker.opserver.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.EncodedResourceResolver;
import org.springframework.web.servlet.resource.VersionResourceResolver;

import java.util.concurrent.TimeUnit;

/**
 * @Description: TODO
 * @Author: tangsw
 * @Date 2020/6/2 14:12
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pub/**")
                .addResourceLocations("/static/", "classpath:/static/")
                .setCacheControl(CacheControl.maxAge(7, TimeUnit.DAYS).cachePrivate())
                .resourceChain(true)
                .addResolver(new EncodedResourceResolver())
                .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"));
    }

}

  

原文地址:https://www.cnblogs.com/tangshengwei/p/13032025.html