thymeleaf 教程

1 怎么使用

前端html页面标签中引入如下:
``

2 表达式

[链接地址:](<>)  
//渲染后的结果  
[链接地址:](</name/3>)

    
    
     * 数学操作  
      * 二元操作:`+, - , * , / , %`
      * 一元操作: `- (负)`
     * 布尔操作
      * 一元 : `and, or`
      * 二元 : `!, not`
     * 比较
      * 比较:`> , < , >= , <= ( gt , lt , ge , le )`
      * 等于:`== , != ( eq , ne )`
     * 条件
      * If-then: `(if) ? (then)`
      * If-then-else: `(if) ? (then) : (else)`
      * Default: `(value) ?: (defaultvalue)`
     * 无操作 
      * 使用`_ `来禁止转义。
    
    ##3 支持的操作  
     * html5的操作支持: 

th:abbr  
th:accept  
th:accept-charset  
th:accesskey  
th:action  
th:align  
th:alt  
th:archive  
th:audio  
th:autocomplete  
th:axis  
th:background  
th:bgcolor  
th:border  
th:cellpadding  
th:cellspacing  
th:challenge  
th:charset  
th:cite  
th:class  
th:classid  
th:codebase  
th:codetype  
th:cols  
th:colspan  
th:compact  
th:content  
th:contenteditable  
th:contextmenu  
th:data  
th:datetime  
th:dir  
th:draggable  
th:dropzone  
th:enctype  
th:for  
th:form  
th:formaction  
th:formenctype  
th:formmethod  
th:formtarget  
th:fragment  
th:frame  
th:frameborder  
th:headers  
th:height  
th:high  
th:href  
th:hreflang  
th:hspace  
th:http-equiv  
th:icon  
th:id  
th:inline  
th:keytype  
th:kind  
th:label  
th:lang  
th:list  
th:longdesc  
th:low  
th:manifest  
th:marginheight  
th:marginwidth  
th:max  
th:maxlength  
th:media  
th:method  
th:min  
th:name  
th:onabort  
th:onafterprint  
th:onbeforeprint  
th:onbeforeunload  
th:onblur  
th:oncanplay  
th:oncanplaythrough  
th:onchange  
th:onclick  
th:oncontextmenu  
th:ondblclick  
th:ondrag  
th:ondragend  
th:ondragenter  
th:ondragleave  
th:ondragover  
th:ondragstart  
th:ondrop  
th:ondurationchange  
th:onemptied  
th:onended  
th:onerror  
th:onfocus  
th:onformchange  
th:onforminput  
th:onhashchange  
th:oninput  
th:oninvalid  
th:onkeydown  
th:onkeypress  
th:onkeyup  
th:onload  
th:onloadeddata  
th:onloadedmetadata  
th:onloadstart  
th:onmessage  
th:onmousedown  
th:onmousemove  
th:onmouseout  
th:onmouseover  
th:onmouseup  
th:onmousewheel  
th:onoffline  
th:ononline  
th:onpause  
th:onplay  
th:onplaying  
th:onpopstate  
th:onprogress  
th:onratechange  
th:onreadystatechange  
th:onredo  
th:onreset  
th:onresize  
th:onscroll  
th:onseeked  
th:onseeking  
th:onselect  
th:onshow  
th:onstalled  
th:onstorage  
th:onsubmit  
th:onsuspend  
th:ontimeupdate  
th:onundo  
th:onunload  
th:onvolumechange  
th:onwaiting  
th:optimum  
th:pattern  
th:placeholder  
th:poster  
th:preload  
th:radiogroup  
th:rel  
th:rev  
th:rows  
th:rowspan  
th:rules  
th:sandbox  
th:scheme  
th:scope  
th:scrolling  
th:size  
th:sizes  
th:span  
th:spellcheck  
th:src  
th:srclang  
th:standby  
th:start  
th:step  
th:style  
th:summary  
th:tabindex  
th:target  
th:title  
th:type  
th:usemap  
th:value  
th:valuetype  
th:vspace  
th:width  
th:wrap  
th:vspace  
th:width  
th:wrap  
th:xmlbase  
th:xmllang  
th:xmlspace
    
    
     * 布尔类型

th:async  
th:autofocus  
th:autoplay  
th:checked  
th:controls  
th:declare  
th:default  
th:defer  
th:disabled  
th:formnovalidate  
th:hidden  
th:ismap  
th:loop  
th:multiple  
th:novalidate  
th:nowrap  
th:open  
th:pubdate  
th:readonly  
th:required  
th:reversed  
th:scoped  
th:seamless  
th:selected
    
    
    ###3.1 常用th标签
    
    关键字| 功能介绍| 案例  
    ---|---|---  
    
    th:value| thymeleaf格式化时间| 

th:value="${#dates.format(info.date, 'yyyy-MM-dd HH:mm:ss')}"  
      
    
    th:id| 替换id|   
      
    
    th:text| 文本替换| 

description  
      
    
    th:utext| 支持html的文本替换| 

content  
      
    
    th:object| 替换对象|   
      
    
    th:value| 属性赋值|   
      
    
    th:with| 变量赋值运算|   
      
    
    th:style| 设置样式|   
      
    
    th:onclick| 点击事件|   
      
    
    th:each| 属性赋值|   
      
    
    th:if| 判断条件|   
      
    
    th:unless| 和th:if判断相反| 

Login  
      
    
    th:href| 链接地址| 

Login  
      
    
    th:switch| 多路选择配合th:case使用|   
      
    
    th:fragment| th:switch的一个分支| 

User is an administrator  
      
    
    th:includ| 布局标签,替换内容到引入的文件|   
      
    
    th:replace| 布局标签,替换整个标签到引入的文件|   
      
    
    th:selectd| selected选择框选中| 

th:selected="(${xxx.id} == ${configObj.dd})"  
      
    
    th:src| 图片类地址引入|   
      
    
    th:inline| 定义js脚本可以使用变量|

last update time 2026-07-07