SpringBoot 结合 Thymeleaf 进行页面的跳转

1、引入thymeleaf依赖

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

2、在application.yml进行thymeleaf配置

# 配置页面地址
spring:     thymeleaf:
      prefix: classpath:/templates/

3、编写Controller

// 服务启动自动跳转首页
@RequestMapping(value = {"/","index"})
public String index(){
  return "index";
}

文件结构:

访问localhost:8080   或者 localhost:8080/index

原文地址:https://www.cnblogs.com/it-noob/p/9999350.html

时间: 2024-08-30 12:04:38

SpringBoot 结合 Thymeleaf 进行页面的跳转的相关文章

springboot~入门第二篇~页面html跳转~

遇到的问题:按照别人的blog搭jsp页面就是html页面跳转不了,总是如图: 终于找到了一个能用的blog ,换 thymeleaf(html页面跳转)成功. 控制器代码 注意下: @Controller而不是@RestController,不然也会直接返回字段值 就变成入门(一)写的内容 import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.Reques

在springboot整合thymeleaf模板引擎中@Controller和@RestController不同注解的跳转页面方法

注:本文纯属学习记录,以备后续查阅! 1.通过@RestController注解实现页面跳转: 对应H5静态页面 2.使用@Controller注解实现页面跳转 对应H5静态页面: 之所以会出现@Controller和@RestController两种注解实现跳转页面不同的方式主要的原因是: 通过@RestController源码知道@RestController是@Controller和@ResponseBody的组合注解 如果需要跳转到指定 的页面,需要使用@Controller注解和视图解

SpringBoot学习------SpringBoot使用Thymeleaf模块访问不了静态页面

SpringBoot使用Thymeleaf模块访问不了静态页面 最近学习SpringBoot的过程中使用了Thymeleaf模块引擎,页面发送请求后老是无法显示静态页面,所有的步骤都是参考资料来执行,自我检查好久都没有找到问题的答案,哎呦,我这暴脾气就上来了,一个小页面就想难倒我?那我还怎么找到ONE PIECE? 下面就给大家分享一下我悲惨的心路历程: 要使用Thymeleaf模块引擎,我们首先在pom文件中引入相关依赖如下: 这边我们不需要指定版本,因为SpringBoot默认会使用spri

Springboot集成Thymeleaf中遇到的问题------不能返回页面,只返回字符串

springboot集成thymeleaf中遇到的问题: 不能返回页面,只返回字符串 原因:在controller中使用了注解@RestController 或者注解@ResponseBody 解决方法:用 @Controller 代替 @RestController: 不使用@ResponseBody注解. 原文地址:https://www.cnblogs.com/BenNiaoXianFei/p/12672384.html

springboot整合Thymeleaf模板引擎

引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>nekohtml</groupId&g

【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限

开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他URL,均跳转至登录页面 ② 登录涉及帐号和密码,帐号错误提示帐号错误,密码错误提示密码错误 ③ 登录成功跳转至首页,首页显示登录者帐号信息,并有注销帐号功能,点击注销退出系统 ------------------------------------------------------------------

Springboot+JPA+Thymeleaf 校园博客完整小网站

本文所属[知识林]:http://www.zslin.com/web/article/detail/35 此项目是一个比较简易的校园博客.麻雀虽小五脏俱全,虽然是比较简易的但是涉及的知识点还是比较全面的. 此项目涵盖了[知识林]中Springboot和Thymeleaf中所有知识点的内容. 主要功能有: 系统管理 系统初始化 菜单管理 角色管理 用户管理 系统配置管理 用户注册 邮件验证码实现 用户登陆 找回密码 博文分类管理 添加分类 修改分类 博文管理 添加博文 修改博文 博文评论(未实现)

Spring Boot入门系列六( SpringBoot 整合thymeleaf)

SpringBoot 整合thymeleaf 一.什么是Thymeleaf模板 Thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎.类似JSP,Velocity,FreeMaker等,它也可以轻易的与Spring MVC等Web框架进行集成作为Web应用的模板引擎.与其它模板引擎相比,Thymeleaf最大的特点是能够直接在浏览器中打开并正确显示模板页面,而不需要启动整个Web应用.它的功能特性如下: @Controller中的方法可以直接返回模板名称,接下来Thyme

SpringBoot学习9:springboot整合thymeleaf

1.创建maven项目,添加项目所需依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <de