Spring Boot定制首页和404页面
2023-06-13 09:12:46 时间
大家好,又见面了,我是你们的朋友全栈君。
一、定制首页:
方式一:SpringBoot自动映射
在静态资源目录resources、static、public的其中一个目录中创建index.html文件,springBoot会自动识别,将这个文件作为首页访问
方式二:使用thymeleaf模板引擎
1.导入依赖
<!--Thymeleaf模板引擎依赖-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
2.resources目录下的templates目录中创建index.html(文件名称不强制,只要与控制层对应就行)
@Controller
public class PageController {
@RequestMapping("/")
public String index(Model model){
model.addAttribute("msg","首页");
return "index"; //thymeleaf引擎帮我们配置好了视图解析器,实际返回的页面为templates目录下的index.html
}
}
二、定制404页面:
在导入了Thymeleaf模板引擎依赖的前提下,定制404页面非常简单,在templates目录下创建error目录,然后error目录中创建404.html,Thymeleaf会自动将这个页面定制为404页面
当然方法肯定还有很多,这里只做推荐
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164564.html原文链接:https://javaforall.cn
相关文章
- Spring 全家桶之 Spring Security(四)
- 开源!一款基于Spring Boot的二维码生成和解析工具
- Spring Boot整合OpenOffice实现Word、Excel、PPT在线预览
- @PostConstruct注解是Spring提供的?今天讲点不一样的「建议收藏」
- Spring Data JPA 之 JpaRepository
- spring boot的基本配置——spring boot的web开发——Thymeleaf模板引擎———通过HttpSession session的session.setAttribute返回数据给
- spring任务调度scheduled_golang 任务调度
- 基于Spring Boot、Vue的考试报名系统设计与实现-前后端分离-课程设计-毕业设计一键部署版
- Spring Boot+Keycloak从零到壹
- Spring - FactoryBean扩展实战_MyBatis-Spring 启动过程源码解读
- 将Bean交给Spring容器管理有几种方式?
- Spring基础(八):注解方式创建对象IOC
- Spring Cloud Sleuth 被官方彻底移除!我真是醉醉的了。。。
- Spring Batch多步骤任务、并行执行、任务决策器、任务嵌套
- Spring Boot的RESTful API开发(一)
- 我的心血全在这了,这种方式讲@Async原理,你别再不懂Spring了
- 查看docker 部署Spring Boot服务控制台信息详解程序员
- spring jdbcTemplate 插入对象返回主键值详解编程语言
- spring的AOP(四)—-Spring AOP 编程(Advisor)详解编程语言
- Spring Cloud 入门教程(一): 服务注册详解编程语言
- Spring Cloud(一):概述以及核心成员介绍详解编程语言
- Spring Boot 2.0官方文档之 Actuator详解编程语言
- Spring Boot2.0之整合Mybatis详解编程语言
- Spring Boot 2 (四):使用 Docker 部署 Spring Boot详解编程语言
- spring Boot(十九):使用Spring Boot Actuator监控应用详解编程语言
- Spring Boot(十五):spring boot+jpa+thymeleaf增删改查示例详解编程语言
- Spring Boot(十四):spring boot整合shiro-登录认证和权限管理详解编程语言
- 使用Spring boot 嵌入的tomcat不能启动: Unregistering JMX-exposed beans on shutdown详解编程语言
- php转java 系列2 Spring boo 链接数据库jdbc详解编程语言
- 为什么说Java程序员到了必须掌握 Spring Boot 的时候?
- Nacos 2.0的Spring Boot Starter来了!