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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Thymeleaf 入门

發布時間:2023/11/27 生活经验 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Thymeleaf 入门 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基本項目結構:

?

Thymeleaf配置:

spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/static/
spring.thymeleaf.suffix=.html

spring默認的模板映射路徑是:src/main/resources/templates 

?ftl路徑的hello.html

<!DOCTYPE html>
<html lang="zh-CN"xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org"><head><title>helloWorld</title></head><body><h1>Hello : <b th:text="${name}">姓名</b></h1></body>
</html>

 TestController:

?

package com.eshore.ismp.web;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;@Controller
public class TestController {@RequestMapping(value = "test", method = RequestMethod.GET)public String test(Model model) {model.addAttribute("name", "MERCY");return "/ftl/hello";}}

運行結果:

?

 

?要注意的點:

spring.thymeleaf.cache要設置為true,以方便開發及時看到頁面刷新

springboot直接引入:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>

非springboot項目引入:

<dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf</artifactId><version>2.1.4</version>
</dependency>
LEGACYHTML5屬性值需要搭配一個額外的庫NekoHTML才可用。主要作用是設置Thymeleaf格式檢查沒這么嚴格,默認屬性值是HTML5

  

  

?

轉載于:https://www.cnblogs.com/JAYIT/p/10444763.html

總結

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

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