静态资源 全局版本号配置

java部分

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import java.util.HashMap;
import java.util.Map;

@Component
public class ViewResolverConfig implements WebMvcConfigurer {

    @Value("${static-resources.version}")
    private String version;

    @Autowired
    @Qualifier("thymeleafViewResolver")
    private ThymeleafViewResolver thymeleafViewResolver;

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        if (thymeleafViewResolver != null) {
            Map<String, Object> map = new HashMap<>();
            map.put("version",version);
            thymeleafViewResolver.setStaticVariables(map);
        }
    }
}

前端部分

    <link th:href="@{favicon.ico}" rel="stylesheet"/>
    <link th:href="@{/css/bootstrap.min.css(v=${version})}" rel="stylesheet"/>
    <link th:href="@{/css/jquery.contextMenu.min.css(v=${version})}" rel="stylesheet"/>
    <link th:href="@{/css/font-awesome.min.css(v=${version})}" rel="stylesheet"/>
    <link th:href="@{/css/animate.css(v=${version})}" rel="stylesheet"/>
    <link th:href="@{/css/style.css(v=${version})}" rel="stylesheet"/>
    <link th:href="@{/css/skins.css(v=${version})}" rel="stylesheet"/>
    <link th:href="@{/ruoyi/css/ry-ui.css(v=${version})}" rel="stylesheet"/>
暂无评论

发送评论 编辑评论


				
上一篇
下一篇