成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

SpringBoot使用Thymeleaf模板引擎訪問靜態(tài)html的過程

瀏覽:7日期:2023-04-15 18:49:15

最近要做一個java web項目,因為頁面不是很多,所以就沒有前后端分離,前后端寫在一起,這時候就用到thymeleaf了,以下是不動腦式的傻瓜教程。。。。。

一:創(chuàng)建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# 配置#thymeleafspring.thymeleaf.cache=falsespring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.check-template-location=truespring.thymeleaf.suffix=.htmlspring.thymeleaf.encoding=UTF-8spring.thymeleaf.servlet.content-type=text/htmlspring.thymeleaf.mode=HTML

四:項目的templates文件夾下新建頁面success.html,如下

SpringBoot使用Thymeleaf模板引擎訪問靜態(tài)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 * 文件說明: */@Controllerpublic class FirstTestController { @RequestMapping(value = 'hello') public String hello(ModelMap modelMap) { modelMap.put('hei', 'thymeleaf'); return 'success'; }}

六:訪問如下,完成

SpringBoot使用Thymeleaf模板引擎訪問靜態(tài)html的過程

到此這篇關(guān)于SpringBoot使用Thymeleaf模板引擎訪問靜態(tài)html的過程的文章就介紹到這了,更多相關(guān)SpringBoot Thymeleaf模板訪問靜態(tài)html內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章: