springboot——7Thymeleaf模板引擎,基础语法

springboot——7Thymeleaf模板引擎,基础语法,第1张

springboot——7Thymeleaf模板引擎,基础语法 Thymeleaf模板引擎

我们为什么不用jsp呢,即熟悉,又方便?
我们用的是嵌入式的Tomcat,所以现在默认是不支持jsp的。

所以那么spring推荐的模板引擎还有些什么?
jsp,thymeleaf,freemarker

模板引擎的思想是

结合模板和数据,解析输出最终页面

第一步引入依赖,现在都是基于3.x版本的才可以用。
了解它
Thymeleaf 官网:https://www.thymeleaf.org/
Thymeleaf 在Github 的主页:https://github.com/thymeleaf/thymeleaf
使用它
Spring官方文档:找到我们对应的版本
https://docs.spring.io/spring-boot/docs/2.2.5.RELEASE/reference/htmlsingle/#using-boot-starter


    org.springframework.boot
    spring-boot-starter-thymeleaf

第二步?没有第二步,在对应目录下写HTML吧
创建一个TestController

@Controller
public class TestController {

    @GetMapping("/thyme")
    public String tyeme(Model model){

        model.addAttribute("msg","快乐的玩耍吧~");
        return "test";
    }
}

创建一个test.html




    
    Title

					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/4998168.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存