一聚教程网:一个值得你收藏的教程网站

热门教程

Java基础之Thymeleaf的简单使用代码示例

时间:2022-06-29 02:29:37 编辑:袖梨 来源:一聚教程网

本篇文章小编给大家分享一下Java基础之Thymeleaf的简单使用代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

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来进行数据的传输
 * @title: Thymeleaf简单使用
 */
@Controller
@RequestMapping("/thyme")
public class ThymeleafController {

    @RequestMapping("data")
    public String ShowData(Model model){
        model.addAttribute("text","点击1");
        model.addAttribute("utext","点击1");
        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";
    }
}    

前端代码




    
    thymeleaf的简单使用









id:


name:






看这里看这里


最终效果

热门栏目