最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java基礎(chǔ)之Thymeleaf的簡單使用

 更新時間:2021年04月28日 11:46:12   作者:小鄭要做干飯人  
這篇文章主要介紹了Java基礎(chǔ)之Thymeleaf的簡單使用,文中有非常詳細的代碼示例,對正在學習java基礎(chǔ)的小伙伴們有非常好的幫助,需要的朋友可以參考下

Java代碼

package com.zzx.controller;

import com.zzx.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Arrays;

/**
 * @date: 2021/04/25/ 10:07
 * @author: ZhengZiXuan
 * @description: 由于Spring Boot 不推薦我們使用.jsp,所以我們就使用html配合thymeleaf來進行數(shù)據(jù)的傳輸
 * @title: Thymeleaf簡單使用
 */
@Controller
@RequestMapping("/thyme")
public class ThymeleafController {

    @RequestMapping("data")
    public String ShowData(Model model){
        model.addAttribute("text","<a href='#'>點擊1</a>");
        model.addAttribute("utext","<a href='#'>點擊1</a>");
        model.addAttribute("value","input值");
        model.addAttribute("user",new User(1,"張三"));
        model.addAttribute("num",100);
        model.addAttribute("flag",true);
        model.addAttribute("list", Arrays.asList("Java","WEB","UI"));
        return "data";
    }
}    

前端代碼

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"><!--此處需要配置thymeleaf,可以不配置,但是會爆紅,不會影響最終效果-->
<head>
    <meta charset="UTF-8">
    <title>thymeleaf的簡單使用</title>
</head>
<body>

<!--取出后的值,填充到p標簽中間,將字符串的標簽解析字符串-->
<p th:text="${text}"></p><br/><hr>

<!--取出后的值,填充到p標簽中間,utext會將字符串的標簽解析為html標簽-->
<p th:text="${utext}"></p><br/>

<!--th:value,相當于是給原value屬性賦值-->
<input th:value="${value}"/><br/><hr/>

<!--thymeleaf支持屬性導航, 對象.屬性-->
id:<p th:text="${user.id}"></p><br>
name:<p th:text="${user.name}"></p><br>
<br><hr/>
<p th:text="${num}"></p>
<br/><hr/>

<!--th:if 判斷,如果判斷成功,該標簽內(nèi)的內(nèi)容會展示,否則不展示-->
<p th:if="${flag}== true">
    看這里看這里
</p>
<hr>
<ol>
    <!--th:each 變量
        1. th:each 屬性在哪個標簽,哪個標簽循環(huán)出現(xiàn)
        2. th:each= "遍歷得到結(jié)果變量 :${key}"
        3. 在當前標簽,或者內(nèi)部標簽就可以使用"遍歷得到結(jié)果變量"
    -->
    <li th:text="${str}" th:each="str : ${list}"></li>
</ol>
</body>
</html>

最終效果

在這里插入圖片描述

到此這篇關(guān)于Java基礎(chǔ)之Thymeleaf的簡單使用的文章就介紹到這了,更多相關(guān)Java Thymeleaf的使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

乌拉特中旗| 萨嘎县| 临汾市| 喀什市| 嘉祥县| 黄浦区| 长泰县| 遂溪县| 宜君县| 札达县| 称多县| 平原县| 通城县| 疏勒县| 定边县| 凭祥市| 治多县| 天柱县| 惠东县| 桐柏县| 山阳县| 东莞市| 囊谦县| 恩平市| 明光市| 珠海市| 高淳县| 固阳县| 香格里拉县| 崇文区| 永和县| 敦煌市| 堆龙德庆县| 武穴市| 双牌县| 云林县| 肇庆市| 普洱| 城口县| 长兴县| 沐川县|