zoukankan      html  css  js  c++  java
  • springboot+thymeleaf不能读取静态资源的问题

    最近用springboot+thymeleaf的时候又发现在运行的时候,静态资源无法展示,网上搜了好多方法:

    方法一:

    在application.properties文件中添加 spring.mvc.static-path-pattern=/static/**

    spring.mvc.static-path-pattern=/static/**

    方法二:

    添加以下类:

     1 import org.springframework.stereotype.Component;
     2 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
     3 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
     4 
     5 
     6 
     7 @Component
     8 public class WebConfig implements WebMvcConfigurer {
     9 /*
    10      * 添加静态资源文件,外部可以直接访问地址
    11      *
    12      * @param registry
    13      */
    14 
    15     @Override
    16     public void addResourceHandlers(ResourceHandlerRegistry registry) {
    17         registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    18     }
    19 }

    除了以上方法我还发现:

    1、更改文件名使其尽量短;

    2、不要在idea工具里面直接粘贴图片,直接拷贝到磁盘里的文件夹下

    有时也可以解决该问题。

  • 相关阅读:
    CSS进阶(八) float
    CSS进阶(七)vertical-align
    CSS进阶(六) line-height
    CSS进阶(五)border
    CSS进阶(四)margin
    CSS进阶(三)padding
    ORA-01555 snapshot too old
    Ubuntu14.04LTS安装引发的蛋疼
    rancher 2 安装 longhorn
    rancher2 挂载ceph-rbd
  • 原文地址:https://www.cnblogs.com/hong-yf/p/14654757.html
Copyright © 2011-2022 走看看