thymeleaf取model值_SpringBoot集成 Thymeleaf,附语法讲解

本文介绍了SpringBoot中如何集成Thymeleaf,并详细讲解了Thymeleaf的常用语法,包括th:text、th:each、th:if等属性的用法,以及代码块表达式、消息表达式、链接表达式和变量表达式的使用。通过实例展示了Thymeleaf在页面渲染和数据绑定上的灵活性。
摘要由CSDN通过智能技术生成

SpringBoot中使用Thymeleaf

  1. pom依赖
                org.springframework.boot            spring-boot-starter-thymeleaf        com.github.theborakompanioni            thymeleaf-extras-shiro            ${thymeleaf-shiro.version}
  1. 配置项
spring:  ## thymeleaf模板设置  thymeleaf:    prefix: classpath:/templates    suffix: .html    mode: HTML    encoding: utf-8    servlet.content-type: text/html    cache: false
  1. 创建LoginController控制器,loginPage函数用来显示登陆页
@Controllerpublic class LoginController {    @GetMapping("/login")    public String loginPage(Model model) {        ProjectProperties properties = SpringApplicationContextUtil.getBean(ProjectProperties.class);        model.addAttribute("isCaptcha", properties.isCaptchaOpen());        return "/login";    }}
  1. 创建templates模板目录,并创建login.html登录页
23d0a0394a6d8269fef813659f966066.png

目录结构

login.html

    EasyBoot登录
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值