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

使用thymeleaf模板引擎

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

使用thymeleaf模板引擎

添加依赖


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

配置文件application.properties

#排除静态文件夹
spring.devtools.restart.exclude=static/**,public/**
#关闭thymeleaf缓存开发过程中无需重启
spring.thymeleaf.cache=false
#设置编码
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.prefix=classpath:/templates/

新建UserController类

@Controller
public class UserController {

    @GetMapping("/addUser")
    public String addUser(Model model){
        model.addAttribute("title","i miss cc very much");
        return "addUser";
    }
}

 

新建addUser.html




    
    Title


标题是:

hello

访问localhost:8080/addUser

 

thymeleaf基础语法

常用的 th 属性

属性含义
th:text文本的赋值及替换
th:value属性赋值
th:each遍历循环一个元素
th:if判断条件,th:unless,th:switch,th:case
th:insert代码块的引入,th:replace,th:include用于公共代码块提取
th:fragment定义代码块,方便被th:insert引用

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

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

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