網站首頁 編程語言 正文
一、freemarker
SpringBoot內部支持Freemarker視圖技術的集成,并提供了自動化配置類FreeMarkerAutoConfiguration,借助自動化配置可以很方便的集成Freemarker基礎到 SpringBoot環境中。
1.引入依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2.查找配置類
在idea上雙擊shift搜索FreeMarkerProperties
,
可以看到,freemareker默認加載路徑是類路徑下一個叫templates
的文件夾,并且后綴默認為.ftlh
。
3.更換配置
如果我們不想用springboot的默認配置,那么可以在application.yml文件中修改這些配置。
spring:
freemarker:
#加載路徑
template-loader-path: classpath:/view/
##后綴
suffix: .ftl
##字符
charset: UTF-8
4.訪問視圖
在resources目錄下新建目錄views,同時新建一個以后綴.ftl
結尾的文件:
<h1>牛馬</h1>
<h2>${msg}</h2>
在controller層編寫方法,訪問視圖:
@RequestMapping("index")
public String index(Model model) {
model.addAttribute("msg", "hello springboot");
return "index";
}
瀏覽器輸入http://localhost:8080/index
,看到如下頁面:
二、thymeleaf
1.引入依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.查找配置類
在idea上雙擊shift搜索ThymeleafProperties
,
可以看到,thymeleaf默認加載路徑是類路徑下一個叫templates
的文件夾,并且后綴默認為.html
。
3.更換配置
如果我們不想用springboot的默認配置,那么可以在application.yml文件中修改這些配置。
spring:
thymeleaf:
# 加載路徑
prefix: classpath:/views/
suffix: .html
4.訪問視圖
在resources目錄下新建目錄views,同時新建一個以后綴.html
結尾的文件:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1 th:text="${msg}"></h1>
</body>
</html>
在controller層編寫方法,訪問視圖:
@RequestMapping("index")
public String index(Model model) {
model.addAttribute("msg", "hello springboot");
return "index";
}
瀏覽器輸入http://localhost:8080/index
,看到如下頁面:
原文鏈接:https://blog.csdn.net/rqt1013_/article/details/125658725
相關推薦
- 2022-06-02 python?面向對象開發及基本特征_python
- 2022-06-16 Linux中Redis安裝部署的操作步驟_Redis
- 2023-11-11 微信 小程序 在電腦PC端無法加載的解決辦法。電腦微信小程序打不開是怎么回事?電腦微信小程序不能打開
- 2023-01-19 Oracle查詢表空間大小及每個表所占空間的大小語句示例_oracle
- 2022-09-29 powershell與cmd的異同匯總_PowerShell
- 2023-02-07 Go動態調用函數的實例教程_Golang
- 2022-06-16 python遺傳算法之單/多目標規劃問題_python
- 2022-05-22 C++11?中的override詳解_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支