发布于2021-05-29 20:55 阅读(806) 评论(0) 点赞(15) 收藏(3)
比如javaweb中的jsp就是一个模板引擎。
为的是可以在html上展示一些特殊的数据的一些特殊的语法
现在比较流行的模板引擎:Thymeleaf、FreeMaker、Velocity还有jsp。
特点:
1.动静分离: Thymeleaf选用html作为模板页,这是任何一款其他模板引擎做不到的!Thymeleaf使用html通过一些特定标签语法代表其含义,但并未破坏html结构,即使无网络、不通过后端渲染也能在浏览器成功打开,大大方便界面的测试和修改。
2.开箱即用: Thymeleaf提供标准和Spring标准两种方言,可以直接套用模板实现JSTL、 OGNL表达式效果,避免每天套模板、改JSTL、改标签的困扰。同时开发人员也可以扩展和创建自定义的方言。
1.导入jar包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.编写controller
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "hello";
}
@RequestMapping("/success")
public String test1(Map<String, Object> map){
map.put("hello", "<h3>你好</h3>");
map.put("users", Arrays.asList("Zzz", "ZZy"));
return "success";
}
}
3.编写页面
必须在templates下面编写.html页面
<body>
<h3>success</h3>
<div th:text="${hello}"></div>
<!--标签一起解析-->
<div th:utext="${hello}"></div>
<hr>
<h4 th:text="${user}" th:each="user:${users}"></h4>
<hr>
<h4>
<span th:each="user:${users}">[[${user}]]</span>
</h4>
</body>
对应的是javaweb的jsp和springmvc的视图解析器
根据视图层的返回success,默认返回的是templates下面的success.html页面
表达式语法
原文链接:https://blog.csdn.net/qq_43141726/article/details/117325700
作者:怎么没有鱼儿上钩呢
链接:http://www.javaheidong.com/blog/article/207301/c2f5cc714644d53fbb75/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!