[SpringBoot]:Thymeleaf学习总结

1.需要在pom文件中引入Thymeleaf(后面缩写成th)

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

 thymeleaf的模板默认路径是resources的templates

2.表达式

变量表达式${}.上下文环境中获取变量值

选择表达式*{}.指定对象中获取变量值 如果没有指定对象即和变量表达式一样

    指定变量 th:object = "${user}"

    <form id="userForm" th:object="${user}">
        <input id="id" name="id" th:value="*{id}"/>
        <input id="username" name="username" th:value="*{username}"/>
        <input id="password" name="password" th:value="*{password}"/>
    </form>

链接表达式@{}.拿静态资源

    <script th:src="@{/webjars/jquery/jquery.js}"></script>

片段表达式~{}.

  ~{ viewName } 表示引入完整页面

  ~{ viewName ::selector} 表示在指定页面寻找片段 其中selector可为片段名、jquery选择器等

  ~{ ::selector} 表示在当前页寻找

    首先通过th:fragment指定片段,然后th:replace路径和名字
    th:replace="~{common/hello::world}"

    简介写法th:replace="common/hello::world"

消息表达式#{}.用于国际化

其他表达式比如${'hello '+(user.name!=null?world:'world and you')}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值