SpringBoot16:thymeleaf取值表达式
2019-05-31 12:00
1201 查看
三种取值表达式
- ${}:变量表达式(见下方使用)
- *{} :选择变量表达式(见下方使用)
- #{...} : Message 表达式,一般用于国际化的取值
前提:我们在model中存了一些数据(包括对象)
[code]@RequestMapping("/testthymeleaf") public String test2(Model model){ System.out.println("laidaole "); model.addAttribute("welcome","springboot----hello"); //存入一个字符串 Hero hero = heroService.getHeroById(2); System.out.println(hero); model.addAttribute("hero",hero);//从数据库中取出一个对象存入model中 return "index"; }
在页面中取值(一般使用第一种方式更加方便明了)
在thymeleaf中,一种标签要在标签尖角括号内写th:xxx (前提要引入约束,见前一篇博客,引入约束后,如果存入的有值,那么写的时候也会自动提示)
[code]<h5>取出存入的字符串</h5> <p th:text="${welcome}">hello</p> <hr> <h5>取出对象第一种方式</h5> <p th:text="${hero.username}"></p> <p th:text="${hero.id}"></p> <p th:text="${hero.phone}"></p> <p th:text="${hero.profession}"></p> <p th:text="${hero.email}"></p> <p th:text="${hero.birthday}"></p> <hr> <h5>取出对象第二种方式</h5> <div th:object="${hero}"> 先取出hero对象,然后再分别取出对象的属性 <p th:text="*{username}"></p> <p th:text="*{id}"></p> <p th:text="*{phone}"></p> <p th:text="*{profession}"></p> <p th:text="*{email}"></p> <p th:text="*{birthday}"></p> </div>
相关文章推荐
- Thymeleaf赋值和取值
- spring boot 与 thymeleaf (2): 常用表达式
- Thymeleaf模板表达式
- 用Thymeleaf在前台下拉列表取值
- C# 正则表达式取值
- 中缀表达式转后缀表达式(用于求字符串表达式值)(js栈和队列的实现是通过数组的push和unshift方法插值,pop方法取值)
- Thymeleaf教程 (五) Thymeleaf标准表达式语法(下)
- struts2 页面标签或ognl表达式取值--未完待续
- ${map.new} javax.el.ELException 表达式取值异常
- 去掉thymeleaf 模板使用'$'符号进行后台变量取值时显示的红色波浪线
- (二)Thymeleaf标准表达式之——简单表达式
- el表达式和ognl表达式如何取值
- EL 表达式 取值将 < 转成 &1t 问题
- SpringBoot24:thymeleaf在js种取值
- Thymeleaf系列四 生成URL地址和表达式工具对象
- <s:if test>的应用及OGNL表达式的取值
- JMeter 正则表达式提取器(后置处理器取值)
- Thymeleaf 快速入门(2)简单表达式
- Thymeleaf模板表达式
- Thymeleaf Javascript 取值