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

歡迎訪問 生活随笔!

生活随笔

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

javascript

第七篇:Spring Boot整合Thymeleaf_入门试炼03

發布時間:2024/9/27 javascript 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第七篇:Spring Boot整合Thymeleaf_入门试炼03 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基本語法實戰案例01

  • 在ThymeleafController中添加此方法
@RequestMapping("/show5")public String showInfo5(Model model) {model.addAttribute("msg", "Thymeleaf 第一個案例");model.addAttribute("key", new Date());return "index5";}
  • 在src/main/resources/templates目錄下面,新建index5.html
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head><meta charset="UTF-8"><title>Thymeleaf入門</title> </head> <body><span th:text="Hello"></span> <hr/> <span th:text="${msg}"></span> <hr/> <input type="text" name="username" th:value="${msg}"/> <hr/> <span th:text="${#strings.isEmpty(msg)}"/> <hr/> <span th:text="${#strings.contains(msg,'9')}"/> <span th:text="${#strings.contains(msg,'T')}"/> <hr/> <span th:text="${#strings.startsWith(msg,'a')}"/> <span th:text="${#strings.startsWith(msg,'T')}"/> <hr/> <span th:text="${#strings.endsWith(msg,'a')}"/> <hr/> <span th:text="${#strings.indexOf(msg,'h')}"/> <hr/> <span th:text="${#strings.substring(msg,13)}"/> <span th:text="${#strings.substring(msg,13,14)}"/> <hr/> <span th:text="${#strings.toUpperCase(msg)}"/> <span th:text="${#strings.toLowerCase(msg)}"/> <hr/> <span th:text="${#dates.format(key)}"/> <hr/> <span th:text="${#dates.format(key,'yyy/MM/dd')}"/> <hr/> <span th:text="${#dates.year(key)}"/> <hr/> <span th:text="${#dates.month(key)}"/> <hr/> <span th:text="${#dates.day(key)}"/> </body> </html>
  • 啟動項目,訪問瀏覽器:http://localhost:8080/show5

基本語法實戰案例02

  • 在ThymeleafController中添加此方法
@RequestMapping("/show2")public String showInfo2(Model model) {model.addAttribute("sex", "男");model.addAttribute("id", "2");return "index2";}
  • 在src/main/resources/templates目錄下面,新建index2.html
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org"> <head><meta charset="UTF-8"><title>Thymeleaf入門</title> </head> <body><span th:if="${sex}=='男'">性別:男</span><span th:if="${sex}=='女'">性別:女</span><div th:switch="${id}"><span th:case="1">id為1</span><span th:case="2">id為2</span><span th:case="3">id為3</span></div> </body> </html>
  • 啟動項目,訪問瀏覽器:http://localhost:8080/show2

基本語法實戰案例03

  • 在ThymeleafController中添加此方法
@RequestMapping("/show3")public String showInfo3(Model model) {List<User> list = new ArrayList<>();list.add(new User(1, "zhangsan", 20));list.add(new User(2, "lisi", 21));list.add(new User(3, "wangwu", 22));model.addAttribute("list", list);return "index3";}
  • 在src/main/resources/templates目錄下面,新建index3.html
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org"> <head><meta charset="UTF-8"><title>Thymeleaf入門</title> </head> <body> <table border="1"><tr><th>ID</th><th>Name</th><th>Age</th><th>Index</th><th>Count</th><th>Size</th><th>Even</th><th>Odd</th><th>First</th><th>Last</th><th>Current</th></tr><tr th:each="u,var:${list}"><td th:text="${u.userid}"></td><td th:text="${u.username}"></td><td th:text="${u.userage}"></td><td th:text="${var.index}"></td><td th:text="${var.count}"></td><td th:text="${var.size}"></td><td th:text="${var.even}"></td><td th:text="${var.odd}"></td><td th:text="${var.first}"></td><td th:text="${var.last}"></td><td th:text="${var.current}"></td></tr> </table> </table> </body> </html>
  • 啟動項目,訪問瀏覽器:http://localhost:8080/show3

基本語法實戰案例04

  • 在ThymeleafController中添加此方法
@RequestMapping("/show4")public String showInfo4(Model model) {Map<String, Object> map = new HashMap<>();map.put("u1", new User(1, "zhangsan", 20));map.put("u2", new User(2, "lisi", 21));map.put("u3", new User(3, "wangwu", 22));model.addAttribute("map", map);return "index4";}
  • 在src/main/resources/templates目錄下面,新建index4.html
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org"> <head><meta charset="UTF-8"><title>Thymeleaf入門</title> </head> <body> <table border="1"><tr><th>ID</th><th>Name</th><th>Age</th></tr><tr th:each="maps :${map}"><td th:text="${maps}"></td></tr> </table> <table border="1"><tr><th>ID</th><th>Name</th><th>Age</th></tr><tr th:each="maps :${map}"><td th:each="entry:${maps}" th:text="${entry.key}"></td><td th:each="entry:${maps}" th:text="${entry.value}"></td></tr> </table> <table border="1"><tr><th>ID</th><th>Name</th><th>Age</th></tr><tr th:each="maps :${map}"><td th:each="entry:${maps}" th:text="${entry.key}"></td><td th:each="entry:${maps}" th:text="${entry.value.username}"></td></tr> </table> <table border="1"><tr><th>ID</th><th>Name</th><th>Age</th></tr><tr th:each="maps :${map}"><td th:each="entry:${maps}" th:text="${entry.value.userid}"></td><td th:each="entry:${maps}" th:text="${entry.value.username}"></td><td th:each="entry:${maps}" th:text="${entry.value.userage}"></td></tr> </table> </body> </html>
  • 啟動項目,訪問瀏覽器:http://localhost:8080/show4

本文源碼下載:

github地址:
https://github.com/gb-heima/Spring-Boot-Actual-Combat/tree/master/parent/spring-boot-chapter-7

總結

以上是生活随笔為你收集整理的第七篇:Spring Boot整合Thymeleaf_入门试炼03的全部內容,希望文章能夠幫你解決所遇到的問題。

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