SpringBoot下的web开发(笔记)

20 篇文章 0 订阅
9 篇文章 0 订阅

web开发

1、创建一个springboot应用,选中我们需要的模块
2、springboot默认将这些场景配置好了,只需要在配置文件指定少量配置就可以运行起来
3、自己编写业务代码

搞清楚自定配置原理这个场景SpringBoot帮助我们配置了什么,能不能修改?修改哪些配置?能不能扩展?
xxxAutoConfiguration :帮我们自动配置组件
xxxProperties:配置类来封装配置文件的内容

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

  public void addResourceHandlers(ResourceHandlerRegistry registry) { 
           if (!this.resourceProperties.isAddMappings()) {   
                  logger.debug("Default resource handling disabled");   
              }
           else {        
                  Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
                  CacheControl cacheControl =this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl();                  				    											    
                if (!registry.hasMappingForPattern("/webjars/**")) {                  
                    this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{"/webjars/**"}).
                    addResourceLocations(new String[{"classpath:/METAINF/resources/webjars/"}).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl));       
             }
            String staticPathPattern = this.mvcProperties.getStaticPathPattern();  
                if (!registry.hasMappingForPattern(staticPathPattern)) 
                {
                     this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[{staticPathPattern}).
                     addResourceLocations(WebMvcAutoConfiguration.getResourceLocations
                      	             (this.resourceProperties.getStaticLocations())).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl));                }        
   }   
    }

所有/webjars/ 都去/META-INF/resources/webjars/找资源webjars以jar包的形式找资源
比如**localhost:8080/webjars/jquery/3.4.1/dist/jquery.js

访问的时候就写webjars下的资源目录
      <dependency>        
          <groupId>org.webjars.bower</groupId>     
                 <artifactId>jquery</artifactId>          
                   <version>3.4.1</version>     
       </dependency>

2)、/** 访问当前项目的任何资源

classpath:/META-INF/resources/",
"classpath:/resources/",
 "classpath:/static/",
 "classpath:/public/

这些资源都是: localhost:8080/abc 里面去找abc

3)、欢迎页:静态资源文件夹下的所有index.html页面:
被 映射比如说 localhost:8080/ 找index页面 springboot做了首页映射 ,直接放在静态资源文件夹下,可以直接被访问到
4)、所有的 **/favicon.icn 图标都是在今天资源文件夹下去找

引入thymeleaf;

(1)导如依

<dependency>			
<groupId>org.springframework.boot</groupId>		
	<artifactId>spring-boot-starter-thymeleaf</artifactId>        
/dependency>

切换thymeleaf版本

<properties>	
	<thymeleaf.version>3.0.10.RELEASE</thymeleaf.version>
<!-- 布局功能的支持程序  thymeleaf3主程序  layout2以上版本 -->
<!-- thymeleaf2   layout1-->
<thymeleaf-layout-dialect.version>3.0.10</thymeleaf-layout-dialect.version>
</properties>

2、Thymeleaf使用(未完待续)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值