静态资源路径

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

classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/ # 默认路径
classpath:/public/

其中 classpath 为 src/main/resources 目录。

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

首页

文件位置:

classpath:/static/favicon.ico
classpath:/templates/index.html

导入 thymeleaf 模板引擎依赖:

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

定义请求控制器:

@Controller
public class IndexController {
@RequestMapping({"/", "/index.html"})
public String index(Model model){
model.addAttribute("msg", "Hello, Thymeleaf!");
return "index";
}
}

加入模板内容显示首页:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>index page</title>
</head>
<body>
<h1>首页</h1>
<div th:text="${msg}"></div>
</body>
</html>

错误页

文件位置:

classpath:/templates/error/404.html
classpath:/templates/error/4xx.html
classpath:/templates/error/500.html
classpath:/templates/error/5xx.html

SpringBoot 之 静态资源路径、显示首页、错误页的更多相关文章

  1. springboot之静态资源路径配置

    静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户直接读取. 在Springboot中默认的静态资源路径有:classpath:/META-INF/resources/,classp ...

  2. Springboot 之 静态资源路径配置

    1.静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户通过浏览器直接读取. 2.在Springboot中默认的静态资源路径有:classpath:/META-INF/resource ...

  3. springboot访问静态资源404

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...

  4. IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404

    IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404 .embody{ padding:10px 10px 10px; margin:0 -20px; borde ...

  5. springboot配置静态资源访问路径

    其实在springboot中静态资源的映射文件是在resources目录下的static文件夹,springboot推荐我们将静态资源放在static文件夹下,因为默认配置就是classpath:/s ...

  6. SpringBoot:静态资源映射、定制404、配置icon

    目录 静态资源映射规则 定制首页 定制错误页面 配置 icon 静态资源映射规则.定制首页.定制404页面.配置网站的图标 静态资源映射规则 SpringBoot中对于静态资源(css,js,img. ...

  7. SpringBoot 配置静态资源映射

    SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...

  8. 13.1Springboot 之 静态资源路径配置

    Spring 静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户直接读取. 在Springboot中默认的静态资源路径有:classpath:/META-INF/resources/ ...

  9. springboot下静态资源的处理(转)

    在SpringBoot中有默认的静态资源文件相关配置,需要通过如下源码跟踪: WebMvcAutoConfiguration-->configureResourceChain(method)-- ...

随机推荐

  1. 智龙开发板搭建llsp环境

    智龙开发板搭建llsp(linux+lighttpd+sqlite3+php)环境 1. 准备 1. 智龙开发板V3 2. 软件编译环境:VirtualBox6+CentOS6.10-i386.min ...

  2. Flutter 中如何优雅的实现多渠道打包(埋点统计系列)

    我是 Zero,脑图先奉上 先赞后看,更新永不断 只要你关注 Flutter,这篇文章你绝对用得着,==> 强烈建议收藏 多渠道打包介绍 多渠道打包的主要作用是满足产品的运营需求,统计渠道和活动 ...

  3. smbclient 使用方法

        1,列出某个IP地址所提供的共享文件夹 smbclient -L 198.168.0.1 -U username%password   2,像FTP客户端一样使用smbclient smbcl ...

  4. BUGKU web刷题记录

    web1 直接F12查看源码,得到flag. web2 直接输入验证码答案,长度被限制,修改可输入长度,提交后得到flag. web3 $what=$_GET['what']; echo $what; ...

  5. LuoguP1619 解一元二次方程的烦恼 题解

    Content 模拟一个系统,给出一个数 \(n\),让你判断是否是素数,如果是合数的话就要质因数分解. 需要注意的几点: 数字超过 \(4\times 10^7\),输出溢出提示. 数字小于 \(2 ...

  6. LuoguP7534 [COCI2016-2017#4] Kartomat 题解

    Content 火车站里头有一个售票机,其键盘可以看作是一个 \(4\times 8\) 的矩阵,其中第一行的前面三个键和最后一行的最后三个键都是 *,剩余的键按照从上到下,从左到右的顺序依次按照 A ...

  7. CF173A Rock-Paper-Scissors 题解

    Content 有 \(2\) 个人在玩石头剪刀布,已知他们的出手都有一定的规律,求 \(n\) 局之后两个人各输了几局. 数据范围:\(1\leqslant n\leqslant 2\times 1 ...

  8. 在JSP页面里,时间控件的JS位置在下面然后就显示不出来

    在JSP页面里,时间空间的JS位置在下面然后就显示不出来,放到前面然后就显示出来了, 情何以堪啊,开始还以为是什么错误.

  9. Java 中的5个代码性能提升技巧,最高提升近10倍

    文章持续更新,可以关注公众号程序猿阿朗或访问未读代码博客. 本文 Github.com/niumoo/JavaNotes 已经收录,欢迎Star. 这篇文章介绍几个 Java 开发中可以进行性能优化的 ...

  10. velocity使用foreach进行遍历时$velocityCount不起作用

    把$velocityCount替换成$foreach.count 例如 #if($foreach.count != $columns.size()),#end