springboot--thymeleaf模板一个简单的web项目

已经学会了怎么建立一个简单的springboot项目,还想要建立一个简单的html页面,如许在Controller中直接能跳转到这个页面 。
于是从网上找各类资本,发现了thymeleaf这个工具,这个工具是springboot保举利用的前台页面模板,利用这个模板也可以获取Controller中的各类参数,很好用,下面就记实一下若何利用它 。
2建立一个简单的springboot项目

需要这些哦
ecplise
thymeleaf
方式/
1起首引入thymeleaf包,将其放在pom.xml文件中 。

springboot--thymeleaf模板一个简单的web项目

文章插图

2其次要知道thymeleaf的默认设置装备摆设,从官网上可以查询到thymeleaf的默认设置装备摆设,如下 。 有一个设置装备摆设就是缓存最好封闭:spring.thymeleaf.cache=false,直接放到application.properties文件中 。

springboot--thymeleaf模板一个简单的web项目

文章插图

3踩过的坑:thymeleaf要求,html文档,必需严酷的有开闭标签,即有<tr>,必需有</tr>;因为是利用ecplise主动建立的html,<meta>标签,并没有</meta>标签,导致法式后台一向报错,加上就好了 。

springboot--thymeleaf模板一个简单的web项目

文章插图

4编写Controller,利用ModelAndview返回到Hello页面(mv.setViewName("Hello")就会指标的目的templates/Hello.html文件;可以看上面的thymeleaf默认设置装备摆设),并携带数据到html页面 。

springboot--thymeleaf模板一个简单的web项目

文章插图

5编写html页面Hello.html 及 application.properties设置装备摆设,如下图

springboot--thymeleaf模板一个简单的web项目

文章插图

springboot--thymeleaf模板一个简单的web项目

文章插图

6【springboot--thymeleaf模板一个简单的web项目】启动项目,打开谷歌浏览器,拜候/sjn/hello办事,查看结果

springboot--thymeleaf模板一个简单的web项目

文章插图


以上内容就是springboot--thymeleaf模板一个简单的web项目的内容啦,希望对你有所帮助哦!

    推荐阅读