当前位置: 首页 > news >正文

哪些网站做农产品电子商务seo就业指导

哪些网站做农产品电子商务,seo就业指导,如何做一个内部网站,网站做排行多少费用文章目录1、静态资源访问1.1、静态资源目录1.2、如果静态资源与controller资源重名1.3、改变默认的静态资源路径1.4、修改静态资源访问前缀1.5、webjar2、欢迎页支持3、自定义 Favicon4、静态资源配置原理4.1、与Web开发有关的相关自动配置类4.2、WebMvcAutoConfiguration 注解…

文章目录

  • 1、静态资源访问
    • 1.1、静态资源目录
    • 1.2、如果静态资源与controller资源重名
    • 1.3、改变默认的静态资源路径
    • 1.4、修改静态资源访问前缀
    • 1.5、webjar
  • 2、欢迎页支持
  • 3、自定义 Favicon
  • 4、静态资源配置原理
    • 4.1、与Web开发有关的相关自动配置类
    • 4.2、WebMvcAutoConfiguration 注解介绍
    • 4.3、WebMvcAutoConfiguration 功能介绍
    • 4.4 WebMvcAutoConfigurationAdapter 内部类
      • 1、唯一有参构造器
      • 2、资源处理的默认规则
    • 4.5 EnableWebMvcConfiguration 内部类
      • 1、欢迎页的处理规则
    • 4.6、favicon


【尚硅谷】SpringBoot2零基础入门教程-讲师:雷丰阳
笔记

路还在继续,梦还在期许

1、静态资源访问

1.1、静态资源目录

默认静态资源放在类路径下: resources 下 /static 或 /public 或 /resources 或 /META-INF/resources 目录下

访问地址: 当前项目根路径/ + 静态资源名

原理: 写静态资源名自动找到静态资源,静态资源映射/**。

spring:# 默认mvc:static-path-pattern: /**

/**的意思是所有文件夹及里面的子文件夹
/*是所有文件夹,不含子文件夹

1.2、如果静态资源与controller资源重名

请求进来,先去找Controller看能不能处理。

不能处理的所有请求又都交给静态资源处理器。

静态资源也找不到则响应404页面

1.3、改变默认的静态资源路径

spring:# 默认mvc:static-path-pattern: /**# 改变默认的静态资源路径resources:static-locations: [classpath:/haha/]

1.4、修改静态资源访问前缀

添加前缀

spring:# 添加前缀mvc:static-path-pattern: /res/**

访问地址:当前项目 + static-path-pattern的值 + 静态资源名 = 静态资源文件夹下找

1.5、webjar

可以自动映射 /webjars/** 下的资源

官网

<dependency><groupId>org.webjars</groupId><artifactId>jquery</artifactId><version>3.5.1</version>
</dependency>

存放路径:META-INF/resources/webjars/jquery/3.5.1/jquery.js

在这里插入图片描述

访问地址:http://localhost:8080/webjars/jquery/3.5.1/jquery.js 后面地址要按照依赖里面的包路径

2、欢迎页支持

  • 静态资源路径下 放 index.html
    • 可以配置静态资源路径
    • 但是不可以配置静态资源的访问前缀。否则导致 index.html不能被默认访问
spring:
#  mvc:
#    static-path-pattern: /res/**   这个会导致welcome page功能失效resources:static-locations: [classpath:/haha/]
  • controller能处理/index

3、自定义 Favicon

favicon.ico 放在静态资源目录下,spring boot 会自动将这个名字的图标当成应用的图标。

spring:
#  mvc:
#    static-path-pattern: /res/**   这个会导致 Favicon 功能失效

4、静态资源配置原理

spring boot 启动时,会默认加载 xxxAutoConfiguration 类(自动配置类),这里从配置类入手查看源码。

4.1、与Web开发有关的相关自动配置类

DispatcherServletAutoConfiguration: 配置SpringNVC中DispatcherServlet

HttpEncodingAutoConfiguration: 配置编解码

MultipartAutoConfiguration: 配置文件上传

ServletWebServerFactoryAutoConfiguration: 配置服务器

WebMvcAutoConfiguration: SpringMVC功能的自动配置类

4.2、WebMvcAutoConfiguration 注解介绍

// 当前类为配置类,组件之间无依赖关系
@Configuration(proxyBeanMethods = false)
// 程序是Servlet应用
@ConditionalOnWebApplication(type = Type.SERVLET)
// 导入Servlet.class, DispatcherServlet.class, WebMvcConfigurer.class 这三个类
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class, WebMvcConfigurer.class })
// 容器中没有 WebMvcConfigurationSupport.class 组件,当前类中配置才生效
@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE + 10)
@AutoConfigureAfter({ DispatcherServletAutoConfiguration.class, TaskExecutionAutoConfiguration.class,ValidationAutoConfiguration.class })
public class WebMvcAutoConfiguration {}

4.3、WebMvcAutoConfiguration 功能介绍

位置:org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration

// SpringMVC用于兼容REST风格
@Bean
@ConditionalOnMissingBean(HiddenHttpMethodFilter.class)
@ConditionalOnProperty(prefix = "spring.mvc.hiddenmethod.filter", name = "enabled", matchIfMissing = false)
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {return new OrderedHiddenHttpMethodFilter();
}// 表单内容过滤器
@Bean
@ConditionalOnMissingBean(FormContentFilter.class)
@ConditionalOnProperty(prefix = "spring.mvc.formcontent.filter", name = "enabled", matchIfMissing = true)
public OrderedFormContentFilter formContentFilter() {return new OrderedFormContentFilter();
}

4.4 WebMvcAutoConfigurationAdapter 内部类

位置:org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter

// Defined as a nested config to ensure WebMvcConfigurer is not read when not
// on the classpath
@Configuration(proxyBeanMethods = false)
@Import(EnableWebMvcConfiguration.class)
// 把配置文件的相关属性与WebMvcProperties=(spring.mvc)、ResourceProperties进行绑定=(spring.resources)
@EnableConfigurationProperties({ WebMvcProperties.class, ResourceProperties.class })
@Order(0)
public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer {}

1、唯一有参构造器

有参构造器所有参数的值都会从容器中确定

形参作用
ResourceProperties resourceProperties;获取和spring.resources绑定的所有的值的对象
WebMvcProperties mvcProperties获取和spring.mvc绑定的所有的值的对象
ListableBeanFactory beanFactorySpring的beanFactory(spring的容器)
HttpMessageConverters找到所有的HttpMessageConverters
ResourceHandlerRegistrationCustomizer找到 资源处理器的自定义器。重点
DispatcherServletPathDispatcherServlet处理的路径
ServletRegistrationBean给应用注册Servlet、Filter…
public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties, WebMvcProperties mvcProperties,ListableBeanFactory beanFactory, ObjectProvider<HttpMessageConverters> messageConvertersProvider,ObjectProvider<ResourceHandlerRegistrationCustomizer> resourceHandlerRegistrationCustomizerProvider,ObjectProvider<DispatcherServletPath> dispatcherServletPath,ObjectProvider<ServletRegistrationBean<?>> servletRegistrations) {this.resourceProperties = resourceProperties;this.mvcProperties = mvcProperties;this.beanFactory = beanFactory;this.messageConvertersProvider = messageConvertersProvider;this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizerProvider.getIfAvailable();this.dispatcherServletPath = dispatcherServletPath;this.servletRegistrations = servletRegistrations;
}

2、资源处理的默认规则

添加资源处理器

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {// 拿到与配置文件绑定的属性spring.resources.add-mappings=true(false禁用静态资源路径映射)if (!this.resourceProperties.isAddMappings()) {//true不进入,false进入logger.debug("Default resource handling disabled");return;}// 获取到配置文件中,静态资源的缓存策略,所有的静态资源在浏览器默认存多少秒Duration cachePeriod = this.resourceProperties.getCache().getPeriod();// 注册第一种访问规则:/webjars/**CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl();// 在项目中寻找静态资源if (!registry.hasMappingForPattern("/webjars/**")) {customizeResourceHandlerRegistration(registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/").setCachePeriod(getSeconds(cachePeriod)).setCacheControl(cacheControl));}// 获取配置文件中spring.mvc.static-path-pattern的值,没有配置就使用默认值:/**String staticPathPattern = this.mvcProperties.getStaticPathPattern();// 在项目中寻找默认位置:{ "classpath:/META-INF/resources/","classpath:/resources/", "classpath:/static/", "classpath:/public/" };// 默认的位置也可以修改if (!registry.hasMappingForPattern(staticPathPattern)) {customizeResourceHandlerRegistration(registry.addResourceHandler(staticPathPattern).addResourceLocations(getResourceLocations(this.resourceProperties.getStaticLocations())).setCachePeriod(getSeconds(cachePeriod)).setCacheControl(cacheControl));}
}
spring:resources:add-mappings: false   #禁用所有静态资源规则cache:period: 1100 # 以秒为单位

4.5 EnableWebMvcConfiguration 内部类

/*** Configuration equivalent to {@code @EnableWebMvc}.*/
@Configuration(proxyBeanMethods = false)
public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration implements ResourceLoaderAware {}

1、欢迎页的处理规则

HandlerMapping:处理器映射,保存了每一个Handler能处理哪些请求。

利用反射向容器中注入WelcomePageHandlerMapping ,作用:寻找谁可以处理欢迎页的映射。

@Bean
public WelcomePageHandlerMapping welcomePageHandlerMapping(ApplicationContext applicationContext,FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) {WelcomePageHandlerMapping welcomePageHandlerMapping = new WelcomePageHandlerMapping(new TemplateAvailabilityProviders(applicationContext), applicationContext, getWelcomePage(),this.mvcProperties.getStaticPathPattern()); // 获取spring.mvc.static-path-pattern 的值welcomePageHandlerMapping.setInterceptors(getInterceptors(mvcConversionService, mvcResourceUrlProvider));welcomePageHandlerMapping.setCorsConfigurations(getCorsConfigurations());return welcomePageHandlerMapping;
}

位置:org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping


final class WelcomePageHandlerMapping extends AbstractUrlHandlerMapping {WelcomePageHandlerMapping(TemplateAvailabilityProviders templateAvailabilityProviders,ApplicationContext applicationContext, Optional<Resource> welcomePage, String staticPathPattern) {// 条件:欢迎页存在,并且路径是默认/**if (welcomePage.isPresent() && "/**".equals(staticPathPattern)) {logger.info("Adding welcome page: " + welcomePage.get());setRootViewName("forward:index.html");}else if (welcomeTemplateExists(templateAvailabilityProviders, applicationContext)) {// 调用Controller看谁能处理/indexlogger.info("Adding welcome page template: index");setRootViewName("index");}}
}

4.6、favicon

与代码无关,浏览器默认发送当前项目下的favicon功能,当添加访问静态资源前缀,就会找不到。

http://www.hkea.cn/news/238625/

相关文章:

  • 阿里巴巴网站国际站建设seo托管服务
  • 企业网站优化之如何做需求分析网奇seo赚钱培训
  • 施工企业会计制度收入确认规定百度自然排名优化
  • 校园网站建设意义网络营销的特点有哪些
  • 内江做网站哪里便宜google搜索关键词热度
  • 福建省建设银行招聘网站网络推广员压力大吗
  • 动态网站订单怎么做搜索引擎优化营销
  • html5行业网站最近有哪些新闻
  • 做网站业务的怎么寻找客户在哪里打广告效果最好
  • 广东深圳seo服务内容
  • 做网站怎么备案网络服务有限公司
  • 网站主页特效欣赏百度官网下载电脑版
  • php mysql开发网站开发任何小说都能搜到的软件
  • the7 wordpress主题宁波seo外包费用
  • 云南建筑培训网seo刷点击软件
  • 男女做暖网站h5页面制作平台
  • 可以做puzzle的网站百度关键词排名提升工具
  • 竞网网站建设南宁网站seo大概多少钱
  • 114黄页信息网宝鸡seo培训
  • 东南亚做棋牌网站挖掘爱站网
  • 中国工程建设招标网官方网站谷歌查询关键词的工具叫什么
  • wordpress管理员密码忘记成都seo招聘
  • 武汉企业建站系统模板下载官方正版百度
  • 上海做网站国际财经新闻
  • 用废旧盒子做家用物品网站seo排名工具
  • 企业铭做网站域名解析在线查询
  • 怎么注册自己的小程序网站优化分析
  • 荆州网站建设流程网站设计培训
  • 网站支付怎么做的seo职业技能培训班
  • 做csgo直播网站上海知名网站制作公司