1 怎么使用
前端html页面标签中引入如下:<html xmlns:th="http://www.thymeleaf.org">
2 表达式
- 简单表达式
- 可用值表达式(后台设置):
${…} - 所有可用值表达式:
*{…}比如*{name} 从可用值中查找name,如果有上下文,比如上层是object,则查object中的name属性。 - 消息表达式:
#{…}国际化时使用,也可以使用内置的对象,比如date格式化数据 - 链接表达式:
@{…}
用来配合link src href使用的语法 - 片段表达式:
~{…}
用来引入公共部分代码片段,并进行传值操作使用的语法。 - 文字
- 文本:
'one text', 'another text', … - 数字:
1,2,1.2,… - 布尔:
true, false - 空值:
null - 单词:
something, main, name, … - 文本操作
- 链接:
+ - 替换:
|The name is ${name}|
“`html
链接地址:
//渲染后的结果
链接地址:
* 数学操作
* 二元操作:`+, - , * , / , %`
* 一元操作: `- (负)`
* 布尔操作
* 一元 : `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标签
<table border="1">
<tr><th>关键字</th><th>功能介绍</th><th>案例</th></tr>
<tr><td>th:value</td><td>thymeleaf格式化时间</td><td>
th:value=”${#dates.format(info.date, ‘yyyy-MM-dd HH:mm:ss’)}”
</td></tr>
<tr><td>th:id</td><td>替换id</td><td>
</td></tr>
<tr><td>th:text</td><td>文本替换</td><td>
description
</td></tr>
<tr><td>th:utext</td><td>支持html的文本替换</td><td>
content
</td></tr>
<tr><td>th:object</td><td>替换对象</td><td>
</td></tr>
<tr><td>th:value</td><td>属性赋值</td><td>
</td></tr>
<tr><td>th:with</td><td>变量赋值运算</td><td>
</td></tr>
<tr><td>th:style</td><td>设置样式</td><td>
</td></tr>
<tr><td>th:onclick</td><td>点击事件</td><td>
</td></tr>
<tr><td>th:each</td><td>属性赋值</td><td>
</td></tr>
<tr><td>th:if</td><td>判断条件</td><td>
</td></tr>
<tr><td>th:unless</td><td>和th:if判断相反</td><td>
</td></tr>
<tr><td>th:href</td><td>链接地址</td><td>
</td></tr>
<tr><td>th:switch</td><td>多路选择配合th:case使用</td><td>
</td></tr>
<tr><td>th:fragment</td><td>th:switch的一个分支</td><td>
User is an administrator
</td></tr>
<tr><td>th:includ</td><td>布局标签,替换内容到引入的文件</td><td>
</td></tr>
<tr><td>th:replace</td><td>布局标签,替换整个标签到引入的文件</td><td>
</td></tr>
<tr><td>th:selectd</td><td>selected选择框选中</td><td>
th:selected=”(${xxx.id} == ${configObj.dd})”
</td></tr>
<tr><td>th:src</td><td>图片类地址引入</td><td>
</td></tr>
<tr><td>th:inline</td><td>定义js脚本可以使用变量</td><td>