SpringBoot 之 静态资源路径、显示首页、错误页
静态资源路径
静态资源支持放在以下路径中,访问优先级从上到下:
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 之 静态资源路径、显示首页、错误页的更多相关文章
- springboot之静态资源路径配置
静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户直接读取. 在Springboot中默认的静态资源路径有:classpath:/META-INF/resources/,classp ...
- Springboot 之 静态资源路径配置
1.静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户通过浏览器直接读取. 2.在Springboot中默认的静态资源路径有:classpath:/META-INF/resource ...
- springboot访问静态资源404
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404
IntelliJ IDEA+SpringBoot中静态资源访问路径陷阱:静态资源访问404 .embody{ padding:10px 10px 10px; margin:0 -20px; borde ...
- springboot配置静态资源访问路径
其实在springboot中静态资源的映射文件是在resources目录下的static文件夹,springboot推荐我们将静态资源放在static文件夹下,因为默认配置就是classpath:/s ...
- SpringBoot:静态资源映射、定制404、配置icon
目录 静态资源映射规则 定制首页 定制错误页面 配置 icon 静态资源映射规则.定制首页.定制404页面.配置网站的图标 静态资源映射规则 SpringBoot中对于静态资源(css,js,img. ...
- SpringBoot 配置静态资源映射
SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...
- 13.1Springboot 之 静态资源路径配置
Spring 静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户直接读取. 在Springboot中默认的静态资源路径有:classpath:/META-INF/resources/ ...
- springboot下静态资源的处理(转)
在SpringBoot中有默认的静态资源文件相关配置,需要通过如下源码跟踪: WebMvcAutoConfiguration-->configureResourceChain(method)-- ...
随机推荐
- linux-源码软件管理-yum配置
总结如下:1.源码配置软件管理2.配置yum本地源和网络源及yum 工作原理讲解3.计算机硬盘介绍 1.1 源码管理软件 压缩包管理命令: # 主流的压缩格式包括tar.rar.zip.war.gzi ...
- 【Java基础】方法调用机制——MethodHandle
MethodHandle是Java7引入的一种机制,主要是为了JVM支持动态语言. 一个MethodHandle调用示例 共有方法调用 首先,演示一下最基本的MethodHandle使用. 第一步:创 ...
- 为什么volatile能保证有序性不能保证原子性
对于内存模型的三大特性:有序性.原子性.可见性. 大家都知道volatile能保证可见性和有序性但是不能保证原子性,但是为什么呢? 一.原子性.有序性.可见性 1.原子性: (1)原子的意思代表着-- ...
- Mysql配置文件 binlog和慢日志
目录 binlog binlog_format log_slave_updates log-bin|log-bin-index expire_logs_days relay-log|relay-log ...
- pipeline配置java项目
pipeline { agent { label 'slave' } options { timestamps() disableConcurrentBuilds() buildDiscarder( ...
- 听听文档(视频)-Power Pivot
打开微信扫描二维码
- 自动化集成:Pipeline流水语法详解
前言:该系列文章,围绕持续集成:Jenkins+Docker+K8S相关组件,实现自动化管理源码编译.打包.镜像构建.部署等操作:本篇文章主要描述Pipeline流水线用法. 一.Webhook原理 ...
- Java abstract 抽象类 和interface接口的异同点
abstract 抽象类 和interface接口的异同点 相同点: 抽象类和接口都不能实例化,他们都位于继承树顶端,被其他类实现和继承 都可以包含抽象方法,实现接口或者继承抽象类的非抽象类(普通类) ...
- C# Dispose模式
需要明确一下C#程序(或者说.NET)中的资源.简单的说来,C#中的每一个类型都代表一种资源,而资源又分为两类: 托管资源:由CLR管理分配和释放的资源,即由CLR里new出来的对象: 非托管资源:不 ...
- 【论文笔记】 Popularity Bias in Dynamic Recommendation
Popularity Bias in Dynamic Recommendation Authors: Ziwei Zhu, Yun He, Xing Zhao, James Caverlee KDD' ...