如何配置SpringBoot静态资源路径

  介绍

小编这次要给大家分享的是如何配置SpringBoot静态资源路径,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。

<强>静态资源路径

静态资源支持放在以下路径中,访问优先级从上到下:

类路径:/meta - inf/资源/
类路径:/资源/
类路径:/静态/#默认路径
类路径:/公共/

其类路径中为src/main/资源目录。

请求地址为:http://localhost: 8080/xx.js

<强>首页

文件位置:

类路径:/静态/ico
位于类路径:/模板/索引。html

导入thymeleaf模板引擎依赖:

& lt; dependencies>   & lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter   & lt;/dependency>   & lt; dependency>   & lt; groupId> org.thymeleaf   & lt; artifactId> thymeleaf-spring5   & lt;/dependency>   & lt; dependency>   & lt; groupId> org.thymeleaf.extras   & lt; artifactId> thymeleaf-extras-java8time   & lt;/dependency>   & lt;/dependencies>

定义请求控制器:

@ controller   公开课IndexController {   @RequestMapping ({“/?“/index.html"})   公共字符串索引模型(模型){   model.addAttribute (“msg",“你好,Thymeleaf !“);   返回“index";   }   }

加入模板内容显示首页:

& lt; !DOCTYPE html>   & lt; html lang=癳n"xmlns: th=癶ttp://www.thymeleaf.org"比;   & lt; head>   & lt;元charset=癠TF-8"祝辞   & lt; title>指数page   & lt;/head>   & lt; body>   & lt; h2>首页& lt;/h2>   & lt; div th:文本=?{味精}“祝辞& lt;/div>   & lt;/body>   & lt;/html>

看完这篇关于如何配置SpringBoot静态资源路径的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。

如何配置SpringBoot静态资源路径