摘要: 上一篇我们搭建了一个简单的demo,这篇我们来介绍下基于spring boot的web开发的入门内容:Thymeleaf模板、web相关配置、tomcat相关设置等
该篇主要介绍下springboot 和Thymeleaf集成(不具体介绍Thymeleaf语法--关于Thymeleaf语法将单独进行介绍)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
spring-boot很多配置都有默认配置,比如默认页面映射路径为 classpath:/templates/*.html 同样静态文件路径为 classpath:/static/
在application.properties中可以配置thymeleaf模板解析器属性.就像使用springMVC的JSP解析器配置一样
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties
这个类,上面的配置实际上就是注入到该类中的属性值.编写一个conntroller提供测试数据(这里牵涉到一点和spring mvc相关的内容,我们后面再介绍,先忽略),代码如下
代码解释:提供一个userList方法返回的model中包含一个user数组和count,user是一个普通的实体类,里面有id,age,name三个属性。 方法是完全spring MVC的内容(如果不熟的朋友请先熟悉下再看后续文章)
放到src/main/resources/templates目录下,这是spring boot和Thymeleaf集成的默认配置路径
访问http://localhost:8080/user/userList,即可看到模板获取到后台数据后渲染到页面。
好了,这篇就先到这里,敬请期待下一篇:springboot 入门教程-的运行原理,关键注解和配置。