zoukankan      html  css  js  c++  java
  • zuul(springboot)设置静态资源代理和默认首页代码一例

    直接上代码:

    public class StaticResourcesConfig extends WebMvcConfigurerAdapter {
    private static final Log log = LogFactory.getLog(StaticResourcesConfig.class);
    
        @Override
        /**
         * 设置默认首页
         */
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/").setViewName("redirect:/index.html");
            registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
            super.addViewControllers(registry);
        }
    
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/path/**").addResourceLocations("file:/html/);
    
        }
    }

    第二个方法可以添加静态资源映射,

    在linux下,如果通过http://[server ip]/path/index.html进行访问,则可以访问到磁盘路径为  /html/index.html 的文件

    在windows下则可以将代码中的 /html/ 换成 [盘符]:/html/ D:/html/

    提醒一下:

    如果用的是容器,不要忘记目录映射

  • 相关阅读:
    Path Sum
    Binary Tree Level Order Traversal II
    Jump Game
    leedcode 刷题-V2
    (2016 年) githup 博客地址 : https://github.com/JMWY/MyBlog
    算法分类总结
    剑指 Offer 题目汇总索引
    LeedCde 题解目录
    趣味算法总目录
    常用
  • 原文地址:https://www.cnblogs.com/flying607/p/9301439.html
Copyright © 2011-2022 走看看