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
<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>