springboot thymelea引擎和语法
thymelea文档: https://zhuanlan.zhihu.com/p/183831446
https://raledong.gitbooks.io/using-thymeleaf/content/Chapter3/section3.1.html
语法
- 简单表达式 Simple Expressions:
- 变量表达式 Variable Expressions: ${...}
- 选中变量表达式 Selection Variable Expressions: *{...}
- 消息表达式 Message Expressions: #{...}
- 连接URL表达式 Link URL Expressions: @{...}
- 片段表达式 Fragment Expressions: ~{...}
- 常量 Literals
- 文本常量 Text literals: 'one text', 'Another one!',…
- 数字常量 Number literals: 0, 34, 3.0, 12.3,…
- 布尔常量 Boolean literals: true, false
- 空常量 Null literal: null
- 常符号 Literal tokens: one, sometext, main,…
- 文本操作 Text operations:
- 字符串连接 String concatenation: +
- 常量替换 Literal substitutions: |The name is ${name}|
- 算数操作 Arithmetic operations:
- Binary operators: +, -, *, /, %
- Minus sign (unary operator): -
- 布尔操作 Boolean operations:
- 布尔操作符 Binary operators: and, or
- 布尔否定 一元操作符Boolean negation (unary operator): !, not
- 比较和相等 Comparisons and equality:
- 比较符 Comparators: >, <, >=, <= (gt, lt, ge, le)
- 相等符 Equality operators: ==, != (eq, ne)
- 条件操作符 Conditional operators:
- If-then: (if) ? (then)
- If-then-else: (if) ? (then) : (else)
- 默认值 Default: (value) ?: (defaultvalue)
- 特殊符号 Special tokens:
- 无操作符 No-Operation: _
项目结构
controller
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Arrays;
@Controller
public class HelloController {
@RequestMapping("/test")
public String test(Model model) {
model.addAttribute("msg","hello
");
model.addAttribute("Numbers", Arrays.asList("一","二"));
return "test";
}
}
test.html
Title
test
[[${num}]]