当前位置: 移动技术网 > IT编程>网页制作>CSS > Thymeleaf学习记录(1)--启动模板及建立Demo

Thymeleaf学习记录(1)--启动模板及建立Demo

2018年12月25日  | 移动技术网IT编程  | 我要评论

 

 

 

thymeleaf是什么?

thymeleaf是适用于web和独立环境的现代服务器端java模板引擎。相比于jspthymeleaf更简洁,渲染性能更好,维护性更好它可以xml/xhtml/html5 javascript, css ,甚至文本文件,避免了jsp页面代码与java代码混合的情况,更有利于前后端分离,使用thymeleaf可以实现spring-boot的诸多特性

demo建立:

 

打开ideafile->new project,选择spring initializr

 

下一步

下一步

选中web

然后点击完成,文件结构如下:

添加controller,再com.example.demo下右键,添加class

hellocontroller内容如下:

测试demo,点击demoappcation->右键,run demoappcation 启动项目,输出如下启动成功:

打开浏览器:输入localhost:8080/hello/say显示如下成功。

接下里配置和thymeleaf页面:

再pom.xml文件添加如下内容

<dependency>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starter-thymeleaf</artifactid>
</dependency>

然后导入包,如下所示:

 

 

在templates中新建html file

 

输入html内容:

添加controller映射:

启动项目,访问http://localhost:8080/hello/getpage,出现如下页面,成功!

 

 

 

 

 

 

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网