日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringBoot使用Thymeleaf模板

發布時間:2024/4/14 javascript 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot使用Thymeleaf模板 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

??版權聲明:本文為博主原創文章,轉載請注明出處

Thymeleaf模板簡介

  Thymeleaf模板是一個現代化的服務端java模板引擎對于所有的web和獨立環境

  Thymeleaf的主要目標是為你的開發工作流程帶來優雅自然的模板 ------ HTML能正確的顯示在瀏覽器中,并且也可以作為靜態原型工作,允許開發團隊加強協作

  在有Spring框架的模塊,與您最喜愛的工具的集成為一體,并能插入自己的功能,Thymeleaf是理想的現代化的HTML5 Web開發JVM ------ 雖然它可以做的更多

  摘自官網:http://www.thymeleaf.org/

  也是SpringBoot推薦使用的模板

SpringBoot配置

1. application.yml配置(application.properties同樣)

spring:thymeleaf:prefix: classpath:/templates/ # 必須以/結尾,否則報錯找不到模板suffix: .htmlmode: HTML5encoding: UTF-8cache: false # 關閉緩存,即時刷新。上線后需改為trueservlet:content-type: text/html

2. 實現Controller

package com.imooc.controller;import com.imooc.pojo.User; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping;@Controller @RequestMapping("th") public class ThymeleafController {@GetMapping("/index")public String index(ModelMap map) {map.addAttribute("name", "thymeleaf-imooc");return "thymeleaf/index";}@GetMapping("/center")public String center() {return "thymeleaf/center/center";}@GetMapping("/test")public String test() {User user = new User();return "";}}

3. 創建Thymeleaf模板

  3.1 index.html(位于 templates/thymeleaf/ 目錄下)

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title></title> </head> <body>Thymeleaf模板引擎<h1 th:text="${name}">hello world</h1> </body> </html>

  3.2 center.html(位于 templates/thymeleaf/center/ 目錄下)

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title></title> </head> <body>Thymeleaf模板引擎<h1>center page</h1> </body> </html>

4. 啟動SpringBoot項目,測試即可

?

參考:

https://www.imooc.com/video/16721

轉載于:https://www.cnblogs.com/jinjiyese153/p/8566130.html

總結

以上是生活随笔為你收集整理的SpringBoot使用Thymeleaf模板的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。