Thymeleaf

引入依赖

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

引入名称空间

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

基本语法

1.表达式

${} :获取请求域、session域、对象等
*{} :获取上下文对象值
#{} :获取国际化等值
@{} :生成链接
~{} :相当于jsp:include作用:引入公共页面


字符串用: ''
空值:null
布尔运算:and , or  , ! , not

设置属性值- th:attr

  • 自动配好的策略
所有thyemleaf的配置都在 ThymeleafProperties
配置好了 SpringTemplateEngine
配好了 ThymeleafViewResolver
我们只需要开发页面

技巧

登录页面跳转到主页面,重定向防止表单重复提交
每个由controller跳转的页面都要加上Thymeleaf的名称空间
重定向之后seesion.setAttribu()会失效,得request.setAttribute
全部评论

相关推荐

03-05 12:52
吉林大学 Java
挣K存W养DOG:他的价值在于把他家里积攒的财富回馈给社会
点赞 评论 收藏
分享
Debug_EVE:简历不要做成左右两页的,尽量做成上下一页
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务