zoukankan      html  css  js  c++  java
  • springboot web静态资源访问

    默认支持html,不支持jsp,

    默认的目录在 src/main/resources/static 下,可以直接访问

    如index.html,可以默认的首页。

    这样的默认目录有4个。分别是

    src/main/resources/static                       优先级 3

    src/main/resources/resources                           2

    src/main/resources/public                                  4

    src/main/resouces/META-INF/resources           1

    这4个并存时,优先级是 3241,META-INF下的优先级最高。

    自定义目录,如在resources/下建立taotao,建立一个配置类,MyWebConfig

    @Configuration
    public class MyWebConfig implements WebMvcConfigurer{
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
    
      registry.addResourceHandler("/**").addResourceLocations("classpath:taotao/")
      }
    
    //handler 匹配的是url路径,在Locations中可以加多个地址,优先级是先加的高,如addResourceLocations("classpath:taotao/","classpath:taotao2/")
    }

    WebMvcAutoConfiguration 默认的配置都在这个类中,可以查看源码,找这个类。


    在templates下的,不能默认访问,类似传统的web-inf下的访问权限

  • 相关阅读:
    Luogu3118:[USACO15JAN]Moovie Mooving
    Luogu4137:Rmq Problem/mex
    Luogu3092:[USACO13NOV]No Change
    BZOJ4321: queue2
    BZOJ4650 : [NOI2016]优秀的拆分
    webpack
    sublime eslint setup
    Sublime themes/ lint themes setup
    sublime text 3
    React
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/14388730.html
Copyright © 2011-2022 走看看