./ 当前目录
../ 父级目录
/ 根目录

spring boot 打包时:

The default includes are as follows:  默认包括的文件
public/**, resources/**, static/**, templates/**, META-INF/**, *
The default excludes are as follows:
.*, repository/**, build/**, target/**, **/*.jar, **/*.groovy 默认排除的

1:spring boot 访问直接映射到一下目录,支持  图片、js、css 等资源的访问

Static resources can be moved to /public (or /static or /resources or /META-INF/resources)
in the classpath root.

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

2:可以在 配置文件中做映射解析,例如在static目录下创建html目录,可以做以下映射,不建议使用。

spring.mvc.view.prefix=/html/
spring.mvc.view.suffix=.html

3:配置类做静态资源映射

/**
* 配置静态资源映射
* @author sam
* @since 2017/7/16
*/
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter { @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//将所有/static/** 访问都映射到classpath:/static/ 目录下
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
}

例1:

1.1

配置静态资源映射
    /**
* 配置静态资源映射
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//将所有/static/** 访问都映射到classpath:/static/ 目录下
registry.addResourceHandler("/public/**").addResourceLocations("classpath:/public/js/");
}

1.2 创建静态资源

访问   :http://localhost:8080/public/public.html

结果:public hello js

例2:根据controller做映射

后台映射

    @RequestMapping("/public")
public String test3() {
return "/public/public.html";
}

访问:http://localhost:8080/public

结果:public hello js

spring boot 使用静态资源的更多相关文章

  1. Spring Boot中静态资源(JS, 图片)等应该放在什么位置

    Spring Boot的静态资源,比如图片应该放在什么位置呢, 如果你放在传统WEB共的类似地方, 比如webapp或者WEB-INF下,你会得到一张示意文件未找到的破碎图片.那应该放哪里呢? 百度一 ...

  2. Spring boot 默认静态资源路径与手动配置访问路径的方法

    这篇文章主要介绍了Spring boot 默认静态资源路径与手动配置访问路径的方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下   在application.propertis中配置 ##端口号 ...

  3. Spring Boot 的静态资源处理

    做web开发的时候,我们往往会有很多静态资源,如html.图片.css等.那如何向前端返回静态资源呢?以前做过web开发的同学应该知道,我们以前创建的web工程下面会有一个webapp的目录,我们只要 ...

  4. spring boot 开静态资源访问,配置视图解析器

    配置视图解析器spring.mvc.view.prefix=/pages/spring.mvc.view.suffiix= spring boot 开静态资源访问application.proerti ...

  5. 不常见偏门的Bug,Spring Boot IDEA 静态资源 图片访问404,初学者之殇

    用过Idea朋友都知道,它有一个非常让人喜欢的功能就是:打算在某个a目录下创建一个hello.class文件,那么你仅需要右键点击New-Java Class- 然后输入名字:a.hello 即可. ...

  6. Spring Boot 设置静态资源访问

    问题描述 当使用spring Boot来架设服务系统时,有时候也需要用到前端页面,当然就不可或缺地需要访问其他一些静态资源,比如图片.css.js等文件.那么如何设置Spring Boot网站可以访问 ...

  7. spring boot开发 静态资源加载不出来

    spring boot 1.5 版本之前 不拦截静态资源 springboot 2.x版本 拦截静态资源 private static final String[] CLASSPATH_RESOURC ...

  8. spring boot的静态资源加载

    1.spring boot默认资源处理 Spring Boot 默认为我们提供了静态资源处理,使用 WebMvcAutoConfiguration 中的配置各种属性. spring boot默认加载文 ...

  9. Spring Boot干货:静态资源和拦截器处理

    前言 本章我们来介绍下SpringBoot对静态资源的支持以及很重要的一个类WebMvcConfigurerAdapter. 正文 前面章节我们也有简单介绍过SpringBoot中对静态资源的默认支持 ...

随机推荐

  1. hdu_1086 You can Solve a Geometry Problem too(计算几何)

    http://acm.hdu.edu.cn/showproblem.php?pid=1086 分析:简单计算几何题,相交判断直接用模板即可. 思路:将第k条直线与前面k-1条直线进行相交判断,因为题目 ...

  2. 写一个自定义的控件接口 C#

    以下是我的测试代码:APP_Code/ucInterface.cs /* APP_Code/ucInterface.cs */ /// <summary> /// Summary desc ...

  3. Android手机资料拷贝导出工具 --- 91手机助手

    http://zs.91.com/

  4. C语言assert()函数用法总结

    assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h> void assert( i ...

  5. SDWebImage第三方库使用注意的一些问题

    1.利用"UIImageView+WebCache.h"加载图片数据 例如: UIImage *placeHolderImg = [UIImage imageNamed:@&quo ...

  6. mysql limit 优化

    1.当取出的数据超过20%时,优化器不会使用索引,而是全表扫描: 2.limit和offset的问题,其实是offset的问题,它会导致mysql扫描大量不需要的行然后删掉 如: select * f ...

  7. 关注被关注表设计-UserFollowMapping

    -- ---------------------------- -- Table structure for UserFollowMapping -- ------------------------ ...

  8. ELK之filebeat-redis-logstash-es构架模式

    下载filebeat的rpm包安装filebeat wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.3.0- ...

  9. MapRedece(多表关联)

    多表关联: 准备数据 ******************************************** 工厂表: Factory Addressed BeijingRedStar 1 Shen ...

  10. Django运算符表达式

    在html页面中,加入运算符表达式,进行逻辑判断.可参考手册.我用的Django是2.1版本 view.py中的代码: from django.shortcuts import render from ...