栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot学习(五)——Thymeleaf

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot学习(五)——Thymeleaf

Thymeleaf 初次使用

创建springboot项目,导入Thymeleaf依赖



    org.springframework.boot
    spring-boot-starter-thymeleaf

Controller

@Controller
public class TestController {

    @RequestMapping("t1")
    public String  hello() {
        return "test";
    }
}

在resources下创建templates文件夹,在文件夹下新建test.html




    
    Title


测试页面

启动项目,访问http://localhost:8080/t1

显示动态数据

编写controller

@RequestMapping("/t1")
public String test1(Model model){
    //存入数据
    model.addAttribute("msg","Hello,Thymeleaf");
    //classpath:/templates/test.html
    return "test";
}

html页面




    
    标题


测试页面

启动测试:

再写一个controller

@RequestMapping("/t2")
public String test2(Map map){
    //存入数据
    map.put("msg","Hello");
    map.put("users", Arrays.asList("lisi","zhangsan"));
    //classpath:/templates/test.html
    return "test2";
}

创建一个新的test2.html




    
    标题


测试页面

[[${user}]]

启动项目,访问 http://localhost:8080/t2

Thymeleaf标签

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1005823.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号