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";
}
}
六:访问如下,完成

到此这篇关于SpringBoot使用Thymeleaf模板引擎访问静态html的过程的文章就介绍到这了,更多相关SpringBoot Thymeleaf模板访问静态html内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Java语言实现简单FTP软件 FTP软件效果图预览之上传功能(3)
这篇文章主要为大家详细介绍了Java语言实现简单FTP软件,FTP软件效果图预览之上传功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-03-03
Springboot如何通过yml配置文件为静态成员变量赋值
这篇文章主要介绍了Springboot如何通过yml配置文件为静态成员变量赋值,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-10-10
IDEA配置java开发环境(maven、gradle、tomcat)
这篇文章主要介绍了IDEA配置java开发环境(maven、gradle、tomcat),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-09-09
详解spring Boot 集成 Thymeleaf模板引擎实例
本篇文章主要介绍了spring Boot 集成 Thymeleaf模板引擎实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-09-09


最新评论