首页 > 其他 > 详细

thymeleaf的使用

时间:2021-06-16 10:33:02      阅读:21      评论:0      收藏:0      [点我收藏+]

1,新建ThymeleafContorllor类

package com.xiang.controller;

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

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

@Controller
@RequestMapping("/xiang")

    /*
    thymeleaf 的使用
    */

    @GetMapping("/user/thymeleaf")
    public String thymeleaf(Model model) {
//        传参
        model.addAttribute("name","小不点");
        return "thymeleaf";
    }

}

2,在resources 下的 templates目录下编写前端代码

<!DOCTYPE html>
<!--引命名规则-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>thymeleaf</title>
</head>
<body>
<h1>小向</h1>
<!--绑messages-->
<p th:text="#{user.name}"></p>

<!--绑变量-->
<h3 th:text="${name}"></h3>
</body>
</html>

注,绑messages 的话,需要在resources 目录下新建 messages.properties 文件 (这儿内容如下:)

user.name = 向向

3,运行结果截图

技术分享图片

thymeleaf的使用

原文:https://www.cnblogs.com/d534/p/14887945.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!