SpringBoot使用Thymeleaf模板引擎访问静态html的过程
作者:刘弘扬fine 发布时间:2023-11-25 10:04:44
标签:SpringBoot,Thymeleaf,静态html
最近要做一个java web项目,因为页面不是很多,所以就没有前后端分离,前后端写在一起,这时候就用到thymeleaf了,以下是不动脑式的傻瓜教程。。。。。
一:创建spring boot的web项目,过程略;
二:依赖如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
三:配置文件:application.properties
#端口号
server.port=8099
# 配置
#thymeleaf
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.mode=HTML
四:项目的templates文件夹下新建页面success.html,如下
五:controller
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author liuhongyang
* @2020/10/20 14:35
* 文件说明:
*/
@Controller
public class FirstTestController {
@RequestMapping(value = "hello")
public String hello(ModelMap modelMap) {
modelMap.put("hei", "thymeleaf");
return "success";
}
}
六:访问如下,完成
来源:https://blog.csdn.net/qq_35101267/article/details/109181638


猜你喜欢
- 实现形式elevationMaterial Design提供了View的阴影效果设置。主要由两个属性决定:elevation和transla
- 配置多个别名 typeAliasesPackage<property name="typeAliasesPackage&qu
- 本文实例讲述了C++实现的O(n)复杂度内查找第K大数算法。分享给大家供大家参考,具体如下:题目:是在一组数组(数组元素为整数,可正可负可为
- 最近学了点kotlin的相关知识,顺手写了一个简单的五子棋单机游戏,分享给大家吧!有兴趣的可以看看五子棋界面package wjc.kotl
- 背景随着公司业务越来越复杂,在同一个列表中需要展示各种类型的数据。总体结构ItemViewAdapter: 每种类型的卡片分别都是不同的It
- 文件输出为字符串示例代码:/** * 读取文件为字符串 * * @return */pub
- 本文实例讲述了C#数据结构之单链表(LinkList)实现方法。分享给大家供大家参考,具体如下:这里我们来看下“单链表(LinkList)”
- 上一节我们做好了支付页面的显示,从上一节支
- 本文实例为大家分享了Android实现EventBus登录界面与传值的具体代码,供大家参考,具体内容如下展示效果添加EventBus导入依赖
- 记录自己用java swing做的第一个简易界面。LoginAction.javapackage com.QQUI0819;import j
- Java关系操作符简写介绍eq--等于、neq--不等于、lt--小于、lte--小于等于、gt--大于、gte--大于等于、e
- 官方文档 8.0Spring为不同缓存做了一层抽象,这里通过阅读文档以及源码会对使用以及原理做一些学习笔记。1.简介
- 1.概述1、Spring 是轻量级的开源的 JavaEE 框架2、 Spring 可以解决企业应用开发的复杂性3、Spring 有两个核心部
- 一、题目描述题目实现:使用套接字实现了服务器端与客户端的通信。运行程序,在服务器端的文本框中输入信息,然后按回车键,客户端就会收到服务器端发
- 因为案例比较简单,所以简单用AndroidApplication -> Game -> Stage 搭建框架 一、主入口,无特殊
- 很多童鞋反应在吧项目导入到eclipse(myeclipse)时中文会有乱码,修改了编码格式后还是乱码,这里给大家介绍一下关于中文乱码时修改
- Android launcher中模拟按home键的实现Intent mHomeIntent = new Intent(Intent.ACT
- 在阅读本文之前,大家可以先参考下《多模字符串匹配算法原理及Java实现代码》简介:本文是博主自身对AC自动机的原理的一些理解和看法,主要以举
- 一、概述我们知道,当我们对es发起search请求或其他操作时,往往都是随机选择一个coordinator发起请求。而这请求,可能是该节点能
- Nacos简介Nacos 英文全称为 Dynamic Naming and Configuration Service,是一个由阿里巴巴团队