帅帅的 林财钦_|

园龄:粉丝:关注:

Spring Boot web简介及原理 day04

一、SpringBoot创建web开发(三部曲)

  1.快速构建SpringBoot项目,并以jar包的形式构建

  

 

  2.选择对应的功能模块 (选定场景,配置少量的配置就可运行,不配置有默认值)

   3.编写自己的逻辑代码

二、SpringBoot对静态资源的映射规则

   通过查看WebMvcAutoConfiguration类,可以查看SpringBoot对静态资源存放的位置

     @Override

复制代码
public void addResourceHandlers(ResourceHandlerRegistry registry) {   //添加资源映射
            if (!this.resourceProperties.isAddMappings()) {
                logger.debug("Default resource handling disabled");
                return;
            }
            Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
            CacheControl cacheControl = this.resourceProperties.getCache()
                    .getCachecontrol().toHttpCacheControl();
            if (!registry.hasMappingForPattern("/webjars/**")) {
                customizeResourceHandlerRegistration(registry
                        .addResourceHandler("/webjars/**")
                        .addResourceLocations("classpath:/META-INF/resources/webjars/")   //webjars/**都存放在classpath:
                                                   /META-INF/resources/webjars
.setCachePeriod(getSeconds(cachePeriod)) .setCacheControl(cacheControl)); } String staticPathPattern
= this.mvcProperties.getStaticPathPattern(); if (!registry.hasMappingForPattern(staticPathPattern)) { customizeResourceHandlerRegistration( registry.addResourceHandler(staticPathPattern)      // /**表示访问项目的任何资源,都去(静态资源文件夹) .addResourceLocations(getResourceLocations( this.resourceProperties.getStaticLocations())) .setCachePeriod(getSeconds(cachePeriod)) .setCacheControl(cacheControl)); } }
复制代码

 

   1.既所有的webjars/**资源,都在classpath:/META-INF/resources/webjars中找资源

  什么是webjars?  就是以jar形式的静态资源(如jquery.js)https://www.webjars.org/

 

  

 

  例如可以这么访问:localhost:8080/webjars/jquery/3.3.1-2/jquery.js

 

  2.、/**  表示访问当前项目的任何资源,都去(静态资源文件夹中寻找)

    静态资源文件夹(存放js,css,image等不包括html,html需要使用模板引擎)

  以下是静态资源文件夹的位置

  

    

复制代码
  classpath:/META-INF/resources/,
classpath:/resources/, classpath:/static/,
classpath:/public/"
  "/":  项目的根路径
复制代码

 

    3.欢迎页(首页)

    

  

     欢迎页:静态资源文件夹下的所有index.html,会被显示出来。名字固定。

     

 

  4.项目工程的图标

  

      图标:在静态资源文件夹中存放.ico文件即可显示该图标。固定名字favicon.ico

   

三、模板引擎

   在SpringBoot中不用Jsp页面,而是使用thmeleaf模板。原因是语法更加简单,强大。

    

 

  使用步骤:

    1.在pom.xml中引入thmeleaf约束。将SpringBoot自带的thmeleaf版本覆盖带,使用版本3。   

复制代码
  
  <!--切换thmeleaf版本-->
  <
dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>   <properties> <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version> <!-- 布局功能的支持程序 thymeleaf3主程序 layout2以上版本 --> <!-- thymeleaf2 layout1--> <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version> </properties>
复制代码

 

   2.对thmeleaf的使用

  只要将普通的html页面放在classpath:/templates/   thmeleaf模板引擎就会自动渲染

   

 

本文作者:独而不孤

本文链接:https://www.cnblogs.com/lcaiqin/p/10411591.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   林财钦  阅读(614)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.

作曲 : Reol

作词 : Reol

fade away...do over again...

fade away...do over again...

歌い始めの一文字目 いつも迷ってる

歌い始めの一文字目 いつも迷ってる

どうせとりとめのないことだけど

伝わらなきゃもっと意味がない

どうしたってこんなに複雑なのに

どうしたってこんなに複雑なのに

噛み砕いてやらなきゃ伝わらない

ほら結局歌詞なんかどうだっていい

僕の音楽なんかこの世になくたっていいんだよ

Everybody don't know why.

Everybody don't know why.

Everybody don't know much.

僕は気にしない 君は気付かない

何処にももういないいない

Everybody don't know why.

Everybody don't know why.

Everybody don't know much.

忘れていく 忘れられていく

We don't know,We don't know.

目の前 広がる現実世界がまた歪んだ

目の前 広がる現実世界がまた歪んだ

何度リセットしても

僕は僕以外の誰かには生まれ変われない

「そんなの知ってるよ」

気になるあの子の噂話も

シニカル標的は次の速報

麻痺しちゃってるこっからエスケープ

麻痺しちゃってるこっからエスケープ

遠く遠くまで行けるよ

安定なんてない 不安定な世界

安定なんてない 不安定な世界

安定なんてない きっと明日には忘れるよ

fade away...do over again...

fade away...do over again...

そうだ世界はどこかがいつも嘘くさい

そうだ世界はどこかがいつも嘘くさい

綺麗事だけじゃ大事な人たちすら守れない

くだらない 僕らみんなどこか狂ってるみたい

本当のことなんか全部神様も知らない

Everybody don't know why.

Everybody don't know why.

Everybody don't know much.

僕は気にしない 君は気付かない

何処にももういないいない

Everybody don't know why.

Everybody don't know why.

Everybody don't know much.

忘れていく 忘れられていく

We don't know,We don't know.