thymeleaf 学习记录

来源:互联网 发布:windows原版aero主题 编辑:程序博客网 时间:2024/06/16 09:14

thymeleaf

Author : Janloong Do_O

springboot 配置

spring.thymeleaf.cache=true # Enable template caching.spring.thymeleaf.check-template=true # Check that the template exists before rendering it.spring.thymeleaf.check-template-location=true # Check that the templates location exists.spring.thymeleaf.enabled=true # Enable Thymeleaf view resolution for Web frameworks.spring.thymeleaf.encoding=UTF-8 # Template files encoding.spring.thymeleaf.excluded-view-names= # Comma-separated list of view names that should be excluded from resolution.spring.thymeleaf.mode=HTML5 # Template mode to be applied to templates. See also StandardTemplateModeHandlers.spring.thymeleaf.prefix=classpath:/templates/ # Prefix that gets prepended to view names when building a URL.spring.thymeleaf.reactive.max-chunk-size= # Maximum size of data buffers used for writing to the response, in bytes.spring.thymeleaf.reactive.media-types= # Media types supported by the view technology.spring.thymeleaf.servlet.content-type=text/html # Content-Type value written to HTTP responses.spring.thymeleaf.suffix=.html # Suffix that gets appended to view names when building a URL.spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain.spring.thymeleaf.view-names= # Comma-separated list of view names that can be resolved.

th标签

关键字      功能介绍        案例th:id      替换id          <input th:id="'xxx' + ${collect.id}"/>th:text     文本替换        <p th:text="${collect.description}">description</p>th:utext    支持html的文本替换   <p th:utext="${htmlcontent}">conten</p>th:object    替换对象        <div th:object="${session.user}">th:value    属性赋值        <input th:value="${user.name}" />th:with    变量赋值运算        <div th:with="isEven=${prodStat.count}%2==0"></div>th:style    设置样式            th:style="'display:' + @{(${sitrue} ? 'none' : 'inline-block')} + ''"th:onclick    点击事件          th:onclick="'getCollect()'"th:each    属性赋值            tr th:each="user,userStat:${users}">th:if    判断条件            <a th:if="${userId == collect.userId}" >th:unless    和th:if判断相反        <a th:href="@{/login}" th:unless=${session.user != null}>Login</a>th:href    链接地址              <a th:href="@{/login}" th:unless=${session.user != null}>Login</a> />th:switch    多路选择 配合th:case 使用    <div th:switch="${user.role}">th:case    th:switch的一个分支        <p th:case="'admin'">User is an administrator</p>th:fragment    布局标签,定义一个代码片段,方便其它地方引用    <div th:fragment="alert">th:include    布局标签,替换内容到引入的文件    <head th:include="layout :: htmlhead" th:with="title='xx'"></head> />th:replace    布局标签,替换整个标签到引入的文件    <div th:replace="fragments/header :: title"></div>th:selected    selected选择框 选中    th:selected="(${xxx.id} == ${configObj.dd})"th:src    图片类地址引入          <img class="img-responsive" alt="App Logo" th:src="@{/img/logo.png}" />th:inline    定义js脚本可以使用变量    <script type="text/javascript" th:inline="javascript">th:action    表单提交的地址        <form action="subscribe.html" th:action="@{/subscribe}">th:remove    删除某个属性        <tr th:remove="all">                    1.all:删除包含标签和所有的孩子。                    2.body:不包含标记删除,但删除其所有的孩子。                    3.tag:包含标记的删除,但不删除它的孩子。                    4.all-but-first:删除所有包含标签的孩子,除了第一个。                    5.none:什么也不做。这个值是有用的动态评估。th:attr    设置标签属性,多个属性可以用逗号分隔    比如 th:attr="src=@{/image/aa.jpg},title=#{logo}",此标签不太优雅,一般用的比较少。

表达式基本对象

    在上下文变量评估OGNL表达式时,一些对象表达式可获得更高的灵活性。这些对象将由#号开始引用。    - #ctx: 上下文对象.    - #vars: 上下文变量.    - #locale: 上下文语言环境.    - #httpServletRequest: (仅在web上文)HttpServletRequest 对象.    - #httpSession: (仅在web上文)  HttpSession 对象.  --表达式功能对象    - #dates:java.util.Date对象的实用方法。    - #calendars:和dates类似, 但是 java.util.Calendar 对象.    - #numbers: 格式化数字对象的实用方法。    - #strings: 字符创对象的实用方法: contains, startsWith, prepending/appending等.    - #objects: 对objects操作的实用方法。    - #bools: 对布尔值求值的实用方法。    - #arrays: 数组的实用方法。    - #lists: list的实用方法。    - #sets: set的实用方法。    - #maps: map的实用方法。    - #aggregates: 对数组或集合创建聚合的实用方法。    - #messages: 在表达式中获取外部信息的实用方法。    - #ids: 处理可能重复的id属性的实用方法 (比如:迭代的结果)。