SpringBoot整合thymeleaf的学习

本文介绍了如何在SpringBoot中整合Thymeleaf模板引擎,从Thymeleaf的基本概念到实际集成步骤,包括添加启动器、配置视图解析器、编写Controller和HTML模板,展示了Thymeleaf在渲染数据和遍历集合方面的特点。
摘要由CSDN通过智能技术生成

Thymeleaf简介

Thymeleaf是一个Java模板引擎,支持html、xml、text、javascript、css、raw这几种模型。
使用Thymeleaf首先需要引入命名空间

<html xmlns:th="http://www.thymeleaf.org">

SpringBoot并不推荐使用jsp,但是支持一些模板引擎技术,如:Freemarker,Thymeleaf,Mustache

Thymeleaf集成

(1)引入启动器
(2)SpringBoot会自动为Thymeleaf注册一个视图解析器:ThymeleafViewResolver

  • 默认前缀:classpath:/templates/
  • 默认后缀:.html
    如果我们返回视图:users,会指向到 classpath:/templates/users.html;一般我们无需进行修改,默认即可。
    在这里插入图片描述

测试.

(3)Controller提供数据
使用ModelMap将数据与页面合在一起

    @RequestMapping(path="/test01",method = {
   RequestMethod.GET})
    public String test01(ModelMap modelMap){
    //带数据建议大家使用ModelMap
        //name jack
        modelMap.addAttribute("name","jack");
        return "person-list"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值