SpringBoot2.x入门到项目实战课程系列(第五章)( 四 )
@RequestMapping("/execute")public String execute(Map map) { map.put("name", "程序员星仔"); // classpath:/templates/success.html return "success";}
- 发送 http://localhost:8080/execute 后 ,通过上面代码转到classpath:/templates/success.html
- 导入 Thymeleaf 的名称空间
- 在 html 页面加上以下名称空间, 使用 Thymeleaf 时就有语法提示 。
- 演示 Thymeleaf 语法
hello 成功 这里显示名字
5.3.3 Thymeleaf 语法5.3.3.1 常用属性- 参考 Thymeleaf 官方文档 10 Attribute Precedence
文章插图5.3.3.2 标准表达式语法
- 参考 Thymeleaf 官方文档 4 Standard Expression Syntax
一、Simple expressions(表达式语法) 1. Variable Expressions(变量表达式): ${...} (参考: 4.2 Variables)1)、获取变量值;使用OGNL表达式;2)、获取对象的属性, 调用方法3)、使用内置的基本对象:#ctx : the context object.(当前上下文对象)#vars: the context variables.(当前上下文里的变量)#locale : the context locale. (当前上下文里的区域信息)下面是Web环境下的隐式对象#request : (only in Web Contexts) the HttpServletRequest object.#response : (only in Web Contexts) the HttpServletResponse object.#session : (only in Web Contexts) the HttpSession object.#servletContext : (only in Web Contexts) the ServletContext object.示例: ${session.foo} (用法参考: 18 Appendix A: Expression Basic Objects)4)、使用内置的工具对象:(用法参考: 19 Appendix B: Expression Utility Objects)#execInfo : information about the template being processed.#messages : methods for obtaining externalized messages inside variablesexpressions, in the same way as they would be obtained using #{…} syntax.#uris : methods for escaping parts of URLs/URIs#conversions : methods for executing the configured conversion service(if any).#dates : methods for java.util.Date objects: formatting, componentextraction, etc.#calendars : analogous to #dates , but for java.util.Calendarobjects.#numbers : methods for formatting numeric objects.#strings : methods for String objects: contains, startsWith,prepending/appending, etc.#objects : methods for objects in general.#bools : methods for boolean evaluation.#arrays : methods for arrays.#lists : methods for lists.#sets : methods for sets.#maps : methods for maps.#aggregates : methods for creating aggregates on arrays or collections.#ids : methods for dealing with id attributes that might be repeated(for example, as a result of an iteration). 2. Selection Variable Expressions(选择表达式): *{...} (参考:4.3 Expressions on selections)1)、和${}在功能上是一样 ,额外新增:配合 th:object 使用省得每次写${session.user.firstName}, 直接取出对象 , 然后写对象名即可Name: Sebastian
Email: Saturn
3. Message Expressions(获取国际化内容): #{...} (参考:4.1 Messages) 4. Link URL Expressions(定义URL): @{...} (参考:4.4 Link URLs) 5. Fragment Expressions(片段引用表达式): ~{...} (参考:4.5 Fragments)...二、Literals(字面量) (参考: 4.6 Literals) 1. Text literals: 'one text' , 'Another one!' ,… 2. Number literals: 0 , 34 , 3.0 , 12.3 ,… 3. Boolean literals: true , false 4. Null literal: null 5. Literal tokens: one , sometext , main ,…三、Text operations(文本操作) (参考: 4.7 Appending texts) 1. String concatenation: + 2. Literal substitutions: |The name is ${name}|四、Arithmetic operations(数学运算) (参考: 4.9 Arithmetic operations) 1. Binary operators: + , - , * , / , % 2. Minus sign (unary operator): -五、Boolean operations(布尔运算) 1. Binary operators: and , or 2. Boolean negation (unary operator): ! , not六、Comparisons and equality(比较运算) (参考: 4.10 Comparators and Equality) 1. Comparators: > ,
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 徐福记联手JDL京东物流向数智化转型,首次落地智慧园区项目
- 苹果两款新iPad齐曝光:性能提高、入门款更轻薄、售价便宜
- 运动计数开发项目的对抗赛:飞算全自动软件工程平台碾压传统模式
- RHEL 9提升了x86_64处理器的入门要求
- 江北新区企业院士工作站技术攻关项目立项数位居南京第一
- 入门HiFi享好声,这几款耳机绝对值得入手
- 赞!盐城高新区4个项目入选省级项目立项!
- 威海高新区2项目获2020年度山东省重点研发计划(重大科技创新工程)立项支持
- 浙江公布首批“互联网+”医疗服务价格项目!适用各级公立医疗机构
- 168天封顶!投资56亿重点AI项目将在上海竣工,提供世界领先算力支撑
