Spring Boot中的静态资源应该放在哪里?

Java 专栏收录该内容
¥59.90 ¥99.00
234篇文章

Spring Boot中的静态资源应该放在哪里?

在开发基于Spring Boot的Web应用程序时,我们经常需要处理静态资源,如CSS样式表、JavaScript脚本和图像文件等。Spring Boot提供了默认的静态资源路径和规则,但我们也可以通过配置来自定义这些规则。

默认情况下,Spring Boot将静态资源文件放置在 static 文件夹下。这个文件夹通常位于项目的 classpath(类路径)根目录下。我们可以在这个文件夹中创建一个名为 css 的子文件夹,并将所有的CSS文件放在其中。同样地,我们可以创建一个名为 js 的子文件夹,并将JavaScript文件放在其中。这种组织结构使得我们可以轻松地在HTML文件中引用这些静态资源,如下所示:

<!DOCTYPE html>
<html>
Spring Boot 静态资源访问 深知大多数初中级Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!因此收集整理了一份《Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。 阅读详情

相关推荐

`<artifactId>spring-boot-starter-integration</artifactId>` 是Spring Boot启动器的一部分,它包含了Spring Integratio

通过引入这个starter,你可以在Spring Boot项目中快速集成Spring Integration的功能,如消息传递、事件驱动架构等。对于日期类型的转换,Spring Boot 有预设的全局转换器,它们能自动将请求参数、请求头或模型属性转换成 Java 日期对象。明确映射,它会返回一个通用的错误响应,包含了状态码、消息以及时间戳。具体来说,当你添加这个依赖时,项目会自动配置好与Spring Integration相关的基础设施,这样你就可以方便地创建消息处理器、通道(如MQTT)、以及使用。

[Blog][Domain] programb.blog.csdn.net 1756

【踩坑记录】Thyemleaf找不到html文件(报错:Template might not exist or might not be accessible)

问题概述 今天做一个Springboot+Thyemleaf的项目,我把几个.html文件放在了resources/templates/bill文件夹下: 在controller里的方法,return了一个页面,代码如下: @RequestMapping("/bill/list") public String list(Bill b, Model model){ //获取所有记账类型,并存储在model中供前端使用 List<BillType>

辣辣的博客 677

电影网站增删改查-4 spring boots/MVC/neo4j/thymeleaf 源码分析 实现View 新增过程

以movie新增为例, 使用thymeleaf 框架 ,预先定义好layout.html: html> http-equiv="Content-Type" content="text/html; charset=utf-8"/> http-equiv="pragma" content="no-cache" /> http-equiv="Cache-Control"

理性的浪漫的程序人生 1012

Spring Boot 实战(3)静态资源配置

第一种: 在Springboot中可以直接在配置文件中覆盖默认的静态资源路径的配置信息:#配置定义的资源位置#配置定义的请求url规则第二种: 在SpringBoot开发中,可以在Java代码中覆盖默认静态资源配置@Overrideif(!自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。

2401_84010302的博客 1633

Spring boot 打包jar后静态资源的访问

Spring boot 打包jar后静态资源的访问 背景: Spring boot 打包成jar包后访问不到静态资源 首先spring boot有默认的文件夹设置,且能够自己识别静态资源,下面是spring boot默认的静态文件夹指定: org.springframework.boot.autoconfigure.web.ResourceProperties private static fi...

Pluto的博客 3118

Spring Boot 静态资源处理

一、最笨的方式 二、Spring boot默认静态资源访问方式 三、自定义静态资源目录 四、总结 做web开发的时候,我们往往会有很多静态资源,如html、图片、css等。那如何向前端返回静态资源呢? 以前做过web开发的同学应该知道,我们以前创建的web工程下面会有一个webapp的目录,我们只要把静态资源放在该目录下就可以直接访问。 但是,基于Spring boot的工程并没有这个目录,那我们应该怎么处理? 一、最笨的方式 我们首先来分享一种最笨的办法,就是将静态资源通过流直接返回给前端,

qq3164069700的博客 841

Vue整合到Spring Boot

前端使用Vue,后台使用Spring Boot。

Rhine 1万+

Spring Boot2 系列教程(十一)Spring Boot 中的静态资源配置

当我们使用 SpringMVC 框架时,静态资源会被拦截,需要添加额外配置,之前老有小伙伴在微信上问松哥 Spring Boot 中的静态资源加载问题:“松哥,我的 HTML 页面好像没有样式?”,今天我就通过一篇文章,来和大伙仔细聊一聊这个问题。 1. SSM 中的配置 要讲 Spring Boot 中的问题,我们得先回到 SSM 环境搭建中,一般来说,我们可以通过 <mvc:reso...

weixin_44626952的博客 166

解释Spring Boot中静态资源映射的配置。

虽然Spring Boot提供了便利的默认配置,但在某些情况下,你可能需要对静态资源的映射进行更精细的控制。这可以通过修改Spring Boot的配置来实现。使用application.properties或application.yml配置你可以在或文件中使用属性来自定义静态资源的位置。上述配置表示除了默认位置外,还会从类路径下的目录和文件系统中的目录加载静态资源。使用Java配置如果你需要更加灵活地配置静态资源映射,可以使用Java配置来覆盖默认设置。例如,你可以创建一个实现了接口的类,并重写。

Pmyx_wyh的博客 728

Spring Boot 实战(5)解决 WebMvcConfigurationSupport 静态资源失效问题

从源码看出容器中有@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)这个注解。当容器中没有这个组件的时候,这个自动配置类才生效然而问题又出来了,这样的继承会导致静态资源失效。如何解决这个问题?/**@since 3.1*/这句话大概的意思是,从Spring 5.0 开始,使用java 8 有默认的方法可以直接实现不需要适配器。

m0_60567796的博客 1069

SpringBoot 系列教程(六十四):Spring Boot 中的静态资源到底要放在哪里?

转自江南一点雨:http://springboot.javaboy.org/2019/0408/springboot-static-resources 一、Spring Boot 中的静态资源到底要放在哪里? 当我们使用 SpringMVC 框架时,静态资源会被拦截,需要添加额外配置,之前老有小伙伴在微信上问松哥Spring Boot 中的静态资源加载问题:“松哥,我的HTML页面好像没有样式...

Thinkingcao的专栏 719

Spring.Boot Web开发初始静态资源处理《课时九》

1.在springboot,我们可以使用以下方式处理静态资源。 webjars1ocalhost:8080/webjars/ public,static,/**,resources localhost:8080/ 2.优先级:resources>static>publid

qq_56248592的博客 349

[springboot]整合jsp实现web应用开发

虽然jsp是相对比较过时的技术,但在有些场景下一些旧的项目有向Spring Boot迁移的需求。本文就介绍在Spring Boot项目中如何整合jsp。

字母哥博客 1028

spring boot实战之配置静态资源路径

1.SpringBoot配置文件 spring: mvc: static-path-pattern: /** resources: static-locations: classpath:/static 第一个指定的static-path-pattern为访问静态资源的路径,这个只能配置一个 第二个static-locations指定静态资源在服务器上的位置 cl...

蛐蛐的博客 1871

LabVIEW内存泄漏诊断与优化:从报错到高效运行

本文深入探讨LabVIEW内存泄漏的诊断与优化方法,从理解内存泄漏本质到使用专业工具链进行问题定位,再到高频场景的解决方案和高级优化策略。通过实战案例展示如何解决工业数据采集系统中的内存不足问题,帮助开发者提升LabVIEW应用的稳定性和效率。

moon9的博客 202

保姆级教程:QGC地面站Vehicle Setup全模块配置详解(从固件升级到安全设置)

本文提供QGC地面站Vehicle Setup全模块配置的保姆级教程,涵盖从固件升级到安全设置的完整流程。详细解析二次开发环境准备、传感器校准、飞行模式配置等关键步骤,帮助用户快速掌握无人机配置技巧,确保飞行安全与性能优化。

weixin_28726671的博客 398

Sharding-JDBC 系列专题 - 第九篇:高可用性与集群管理

高可用性是指系统在面对故障(如数据库宕机、网络中断)时,能够快速恢复并继续提供服务。Sharding-JDBC 和 Sharding-Proxy 提供了多种机制支持高可用性,同时需要结合底层数据库的高可用方案(如 MySQL 主从复制、MHA)来实现。高可用性和集群管理是 Sharding-JDBC 和 Sharding-Proxy 在生产环境中成功应用的关键。本篇详细介绍了数据库高可用方案、Sharding-JDBC 的故障切换机制、Sharding-Proxy 的集群部署,以及分布式治理功能。

资深架构师分享:深入剖析软件架构,探讨云计算、微服务、大数据等前沿技术。分享实践经验,促进技术交流,共同构建卓越系统。 1400

SQLite → PostgreSQL 迁移脚本与踩坑清单

本文提供了SQLite迁移到PostgreSQL的两种可靠路径:首选使用pgloader工具自动转换schema和数据,支持类型映射和并行复制;备选方案通过sqlite3导出CSV再用PostgreSQL的COPY命令导入,适合需要自定义清洗的场景。重点介绍了数据类型映射规则、迁移步骤、校验方法和常见问题,包括自增主键、布尔值、时间类型等关键差异处理。迁移后需进行行数核对、哈希抽样等校验,并给出了性能优化建议。最后强调迁移不仅是数据转移,更需要同步升级数据模型和索引策略,根据业务场景选择合适的数据库方案。

aifs2025的博客 1895

el-transfer和el-tree进行结合搞一个树形穿梭框

由于业务需求需要在穿梭框里使用树形结构,但是本身element里并不支持,于是参考了别的大佬发的文章作为思路及后续自己新增了一些处理功能。

bbkhhvv的博客 6310

用yolov8训练自己的模型并调取摄像头实时检测,新手小白超友好教程!逻辑梳理,从0开始逐步实操❤

帮新手小白学会用yolov8,包含多篇高质量博客整理

Lhhhhds的博客 2943

飞书接入OpenClaw:从零到一的保姆级图文教程

本文主要介绍了飞书接入OpenClaw:从零到一的保姆级图文教程,希望能对学习使用OpenClaw 的同学们有所帮助。 文章目录 1. 背景 2. 解决方案 2.1 步骤一:安装插件 2.2 步骤二:创建机器人应用 2.3 步骤三:测试 3. 注意事项

weixin_43178406的博客 13万+

【社招算法经验贴】算法社招记录

总的来说,也是收获了七七八八的offer,给的涨幅40~100%,职级有的可以对标到 p7(但阿里p7是真难a,a不动)。面了一圈下来,感觉大模型也在收缩hc。尤其是多模态相关hc。凭着上学期间做过相关视觉的work和paper,社招虽然能进面试,但是hc少得可怜,多模态已死慎入。还有大模型应用算法给的涨幅,跟搜广推的涨幅差别不大。真正能几百万往上的是基座pretrain/后训练/infra,但是全靠social和conn,hc极少。

Danger的博客 1004

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: Python语言实现录音功能,附完整代码
下一篇: HLS视频录制、M3U8切片录制和FMP4切片录制详解——以拉流RTMP录制HLS切片为例(Java)
普通网友
博客等级 码龄3年 62粉丝 0原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址