springboot resources路径_手把手实现,Spring boot集成模板引擎swagger2实现

上次说过springboot其实就是一个CI工具,如何体验出来CI的作用就是持续集成,它可以集成各种的工具,这里说说关于模板的集成引擎和Swagger。源码:https://github.com/limingios/netFuture/tree/master/源码/『互联网架构』软件架构-Spring boot集成模板引擎实现(86)/

e3263d9c65c041d38eb3fef842d2629a

(一)Spring boot 集成模板引擎实现web应用

  • 静态资源访问

静态资源

js, css, html, 图片,音视频

静态资源路径

系统可以直接访问的路径,且路径下的所有文件均可被用户直接读取。

Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则:

/static,/public,/resources,/META-INF/resources

在classpath下面创建static目录,并且加入一个图片a.png

f9d042f90a494781afa13a72dd1633c3

加入之后,然后不需要重启直接访问:http://localhost:8888/a.jpg

34076c83-1b5a-49ad-ae96-9f5d6beeb189

properties 内修改默认的静态资源目录

spring.resources.static-locations

(二)集成模板引擎

Spring Boot强烈建议使用模板引擎渲染html页面,避免使用JSP,若一定要使用JSP将无法实现Spring Boot的多种特性。Thymeleaf(spring boot推荐), FreeMarker。

  • Thymeleaf

Spring boot默认的模板配置路径为:src/main/resources/templates。当然也可以修改这个路径,通过配置文件的属性,这个在上次的配置的文件的里面有详细的解释配置里面有。

4bdd12045c1b4f97bec1c891265a69e1

集成Thymeleaf步骤

1.修改pom.xml, 增加如下依赖。

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

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值