$.对前端js类库和框架的引用

使用webjars打包成jar的形式进行引用

webjars地址:https://www.webjars.org/;

选择使用版本-- >   选择管理方式-->  复制依赖到项目的pom。xml中 。

等到依赖的加载完成 ,查看是否存在当前环境中

运行jquery包 ,测试是否可用。

浏览器url输入相关url地址:例如:

http://localhost:5200/webjars/jquery/3.3.1-2/jquery.js

添加成功!

2.直接饮用

在对相关web的自动装配 类的查看中,发现有很多中对静态资源映射的方法,

截取部分ResourseProperties.class类中的部分代码

  1. @ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false)
  2. public class ResourceProperties {
  3.  
  4. //资源根路径
  5. private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
  6. "classpath:/META-INF/resources/", "classpath:/resources/",
  7. "classpath:/static/", "classpath:/public/" };
  8.  
  9. /**
  10. * Locations of static resources. Defaults to classpath:[/META-INF/resources/,
  11. * /resources/, /static/, /public/].

综合源码的定义 ,推荐有以下几种静态资源的映射方法:  /根路径。

3.index.html

对于大部分学习SpringBoot的都会经历一个坎,使用localhost:8080/会显示一个错误页面 并且报(status=404)。

解决springboot因启动项是否在controller等其他类之上的问题。

实际上在不存在index.html 发起一个空的url地址会报404,因为Springboot会自动去寻找index.html 并去优先加载。

  1. @Bean
  2. //配置欢迎页index.html
  3. public WelcomePageHandlerMapping welcomePageHandlerMapping(
  4. ApplicationContext applicationContext) {
  5. return new WelcomePageHandlerMapping(
  6. new TemplateAvailabilityProviders(applicationContext),
  7. applicationContext, getWelcomePage(),
  8. this.mvcProperties.getStaticPathPattern());
  9. }

Ctrl 进

  1. getWelcomePage()方法
  1. static String[] getResourceLocations(String[] staticLocations) {
  2. String[] locations = new String[staticLocations.length
  3. + SERVLET_LOCATIONS.length];
  4. System.arraycopy(staticLocations, 0, locations, 0, staticLocations.length);
  5. System.arraycopy(SERVLET_LOCATIONS, 0, locations, staticLocations.length,
  6. SERVLET_LOCATIONS.length);
  7. return locations;
  8. }
  9.  
  10. private Optional<Resource> getWelcomePage() {
  11. String[] locations = getResourceLocations(
  12. this.resourceProperties.getStaticLocations());
  13. return Arrays.stream(locations).map(this::getIndexHtml)
  14. .filter(this::isReadable).findFirst();
  15. }
  16.  
  17. //获取首页html
  18. private Resource getIndexHtml(String location) {
  19. return this.resourceLoader.getResource(location + "index.html");
  20. }
  1.  
  1. public void setStaticLocations(String[] staticLocations) {
  2. this.staticLocations = appendSlashIfNecessary(staticLocations);
  3. }
  4.  
  5. private String[] appendSlashIfNecessary(String[] staticLocations) {
  6. String[] normalized = new String[staticLocations.length];
  7. for (int i = 0; i < staticLocations.length; i++) {
  8. String location = staticLocations[i];
  9. normalized[i] = location.endsWith("/") ? location : location + "/";
  10. }
  11. return normalized;
  12. }
  1. 获取到首页资源并和路径拼接形成欢迎页自动映射index.html

所以将自动进入index.html 如果查询不到index.html的存在将会(status=404)。

查不到index.html。

 成功界面!

 4.

我注意到下面还有个方法

  1. @Bean
  2. public SimpleUrlHandlerMapping faviconHandlerMapping() {
  3. SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
  4. mapping.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
  5. mapping.setUrlMap(Collections.singletonMap("**/favicon.ico",
  6. faviconRequestHandler()));
  7. return mapping;
  8. }

更改这些小图标的。

添加一个以此命名的图片当做小图标,

SprngBoot对静态资源的映射的更多相关文章

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

    在WebMvcAutoConfiguration类中有相对应的方法addResourceHandlers public void addResourceHandlers(ResourceHandler ...

  2. SpringBoot 对静态资源的映射规则

    一.所有 /webjars/** ,都去 classpath:/META-INF/resources/webjars/ 找资源 webjars:以jar包的方式引入静态资源,如下:引入 jquery ...

  3. 【串线篇】spring boot对静态资源的映射规则

    WebMvcAutoConfiguration的内部类 WebMvcAutoConfigurationAdapter 其中ResourceProperties点进去 其中addResourceHand ...

  4. SpringBoot中的五种对静态资源的映射规则

    目录 1.​ webjars:以jar包的方式引入静态资源 2./** 访问当前项目的任何资源 3.首页index.html,被" /** "映射 4.自定义图标 / favico ...

  5. Spring Boot对静态资源的映射规则

    规则一:所有 " /webjars/** " 请求都去classpath:/META-INF/resources/webjars/找资源 webjars:以jar包的方式引入静态资 ...

  6. JavaEE开发之SpringMVC中的静态资源映射及服务器推送技术

    在上篇博客中,我们聊了<JavaEE开发之SpringMVC中的自定义拦截器及异常处理>.本篇博客我们继续的来聊SpringMVC的东西,下方我们将会聊到js.css这些静态文件的加载配置 ...

  7. springboot06(静态资源映射)

    xxxxAutoConfiguration xxxxproperties 对静态资源的映射规则 webjars @ConfigurationProperties(prefix = "spri ...

  8. 零基础学习java------39---------json格式交互,Restful(不懂),静态资源映射,SSM整合(ssm整合思想,application.xml文件详解(声明式事务管理),)

    一. json格式交互(知道) 1 . 回顾ajax基本语法 $.ajax({ url:"", // 请求的后台路径 data:{"":"" ...

  9. Spring Boot 静态资源处理

    spring Boot 默认的处理方式就已经足够了,默认情况下Spring Boot 使用WebMvcAutoConfiguration中配置的各种属性. 建议使用Spring Boot 默认处理方式 ...

随机推荐

  1. python:窗口化和制作图形

    #圆 from tkinter import * canvas = Canvas(width=800, height=600, bg='yellow')#声明窗口属性 canvas.pack(expa ...

  2. ASP .NET core 入门基础内容备份

    model 里边设置主键 : [key]可以自定义主键 默认是名称为ID类型为int的字段 设置显示格式: [DisplayFormat(DataFormatString="{0:显示的格式 ...

  3. 最近学习的sql查询语句连接查询,标记一下

    select wordbase.name,wb.name,wordconnection.wordid,wordconnection.aid,wordbase.goodsid,goods.hscode, ...

  4. 【bzoj3239】Discrete Logging

    [吐槽] 这题和[bzoj]2480一毛一样. 就是输入顺序和输出变了一下. 传送门:http://www.cnblogs.com/chty/p/6043707.html

  5. spring4-2-bean配置-4-bean之间的关系

  6. freemaker 课程

    品优购电商系统开发 第12章 网页静态化解决方案-Freemarker 传智播客.黑马程序员 1.网页静态化技术Freemarker 1.1为什么要使用网页静态化技术 网页静态化解决方案在实际开发中运 ...

  7. 启动redis注意事项

    1.需要修改配置文件 redis.conf 三处 a.将bind 127.0.0.0    修改为  bind 0.0.0.0 b.daemonize no      修改为   daemonize ...

  8. p4042 [AHOI2014/JSOI2014]骑士游戏

    传送门 分析 我们发现对于一个怪物要不然用魔法代价使其无需考虑后续点要么用普通攻击使其转移到他所连的所有点上且所有边大于0 所以我们可以先将一个点的最优代价设为魔法攻击的代价 之后我们倒着跑spfa求 ...

  9. qy Undefied index报错

    目测是不支持如下写法 $value['status'] = $map[$value['status']];

  10. rocketmq配置项说明(对应版本:4.0.0-incubating)

    Broker配置参数说明 自定义客户端行为 ※一些默认配置的源代码路径 org.apache.rocketmq.store.config --END--