上次说过springboot其实就是一个CI工具,如何体验出来CI的作用就是持续集成,它可以集成各种的工具,这里说说关于模板的集成引擎和Swagger。源码:https://github.com/limingios/netFuture/tree/master/源码/『互联网架构』软件架构-Spring boot集成模板引擎实现(86)/
(一)Spring boot 集成模板引擎实现web应用
- 静态资源访问
静态资源
js, css, html, 图片,音视频
静态资源路径
系统可以直接访问的路径,且路径下的所有文件均可被用户直接读取。
Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则:
/static,/public,/resources,/META-INF/resources
在classpath下面创建static目录,并且加入一个图片a.png
加入之后,然后不需要重启直接访问:http://localhost:8888/a.jpg
properties 内修改默认的静态资源目录
spring.resources.static-locations
(二)集成模板引擎
Spring Boot强烈建议使用模板引擎渲染html页面,避免使用JSP,若一定要使用JSP将无法实现Spring Boot的多种特性。Thymeleaf(spring boot推荐), FreeMarker。
- Thymeleaf
Spring boot默认的模板配置路径为:src/main/resources/templates。当然也可以修改这个路径,通过配置文件的属性,这个在上次的配置的文件的里面有详细的解释配置里面有。
集成Thymeleaf步骤
1.修改pom.xml, 增加如下依赖。
org.springframework.boot spring-boot-starter-thymeleaf
2.编写Controller
import org.springframework.stereotype.Controller;import org.springframework.ui.ModelMap;import org.springframework.web.bind.annotation.RequestMapping;/** * @program: springboot3d * @description: ${description} * @author: LiMing * @create: 2019-06-09 09:15 **/@Controllerpublic class SampleController { @RequestMapping("/testThymeleaf") public String testThymeleaf(ModelMap map) { // 设置属性 map.addAttribute("name