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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

springboot学习笔记(十)

發布時間:2025/3/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot学习笔记(十) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

springboot與動態資源

springboot默認不支持jsp。

推薦使用模板引擎(thymeleaf)進行組裝:

?網頁=模板+數據

此處我們使用的模板引擎是thymeleaf

示例:

引入thymeleaf依賴:

<!-- 引入thymeleaf依賴 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf-spring5</artifactId></dependency><dependency><groupId>org.thymeleaf.extras</groupId><artifactId>thymeleaf-extras-java8time</artifactId></dependency>

thymeleaf簡單入門

1.代碼在哪里寫?

通過源碼得知,只需要將thymeleaf文件放入"classpath:/templates/",并且文件的后綴是".html"即可。

?2.示例:

首先定義一個控制器:

package com.example.demo.controller;import java.util.Map;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping;@Controller public class BootController {@RequestMapping("welcome")public String welcome(Map<String,Object> map) {map.put("welcome", "welcome thymeleaf");return "result";} }

?在內路徑的templates中新建一個html頁面

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body><p th:text = "${welcome}">thymeleaf</p> </body> </html>

測試

總結:

th: 替換原來html的值

如果沒有獲取到${welcome},則顯示thymeleaf

反之,顯示獲取到的值。

Thymeleaf使用介紹

官方文檔可以去官網上下載!https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.pdf

th:的取值問題(第十章)

th:xx

th:text? 獲取文本值,轉義

th:utext? 獲取文本值,不轉義

示例:

<h1>hello</h1>

th:text? 顯示將hello渲染為h1后的效果

th:utext? 顯示<h1>hello</h1>,不渲染

符號問題(第四章)

遍歷問題:

<table> <tr> <th>NAME</th> <th>PRICE</th> <th>IN STOCK</th> </tr> <tr th:each="prod : ${prods}"> <td th:text="${prod.name}">Onions</td> <td th:text="${prod.price}">2.41</td> <td th:text="${prod.inStock}? #{true} : #{false}">yes</td> </tr> </table>

不知不覺,springboot基礎已經快學完了!希望能盡快的用到,哈哈哈,高興!

總結

以上是生活随笔為你收集整理的springboot学习笔记(十)的全部內容,希望文章能夠幫你解決所遇到的問題。

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