SpringBoot如何访问html和js等静态资源配置
作者:祗是辉哥哥 时间:2023-08-17 08:07:43
SpringBoot访问html和js等静态资源配置
把静态资源放到resources/static下,这是springboot静态资源默认访问路径。
在浏览器直接ip:端口/静态资源 就可以了
下面的废话是好久之前写的,不用看了。。。
SpringBoo推荐使用thymeleaf模板作用前端页面展示,整体结构如下所示:
这里我并没有引入thymeleaf模板,所以页面放在了pages目录下。
application.yml配置如下:
server:
port: 9000
context-path: /sso
address: sso.server
spring:
mvc:
static-path-pattern: /**
# 默认值为 classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
我设置了context-path,所以访问的路径前缀都要有/sso。
1:访问html
在controller访问html:
@RequestMapping("/user/login")
public String login(){
return "/pages/login.html";
}
注解必须为@controller
2:访问js
在页面引入js文件:
<script src="/sso/js/jquery-3.3.1.js"></script>
访问该页面显示js文件加载完成。
SpringBoot访问不到js,css等静态资源问题
在网上找了一大部分回答都没解决问题,所以记录一下;
今天碰到这个问题,自己的thymeleaf导入文件的格式也没啥问题,最后点击maven中clean重启下就可以了
来源:https://blog.csdn.net/weixin_42456466/article/details/80688681
标签:SpringBoot,html,js,静态资源,配置
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android实现圆形渐变加载进度条
2021-07-17 18:38:06
![](https://img.aspxhome.com/file/2023/8/137818_0s.jpg)
Android应用框架之应用启动过程详解
2023-06-05 02:20:47
Java 按行读取文件按行写入文件并以空格分割字符串的方法
2023-08-31 12:32:21
android UI绘制加减号按钮
2023-09-11 02:55:28
![](https://img.aspxhome.com/file/2023/1/128981_0s.jpg)
Java String 字符串常量池解析
2023-01-08 19:44:05
![](https://img.aspxhome.com/file/2023/6/66936_0s.png)
Android继承现有控件拓展实现自定义控件textView
2021-05-29 06:29:15
![](https://img.aspxhome.com/file/2023/3/138023_0s.png)
Android studio实现画板功能
2022-08-04 21:30:39
![](https://img.aspxhome.com/file/2023/2/137172_0s.png)
Java单例模式实现静态内部类方法示例
2021-08-03 00:36:51
Netty分布式pipeline管道创建方法跟踪解析
2023-11-03 02:55:51
![](https://img.aspxhome.com/file/2023/0/58890_0s.png)
Android canvas drawBitmap方法详解及实例
2021-06-12 12:17:18
![](https://img.aspxhome.com/file/2023/9/116039_0s.png)
Android自定义控件实现圆形进度CircleProgressBar
2023-04-16 08:24:50
![](https://img.aspxhome.com/file/2023/6/120086_0s.jpg)
通过Docker启动Solace并在Spring Boot通过JMS整合Solace的操作方法
2023-07-11 09:52:28
![](https://img.aspxhome.com/file/2023/7/57507_0s.png)
Android基础之隐藏标题栏/设置为全屏/横竖屏切换
2022-06-22 14:29:35
![](https://img.aspxhome.com/file/2023/8/137468_0s.jpg)
Android布局中gravity与layout_gravity属性说明
2021-08-27 10:51:31
![](https://img.aspxhome.com/file/2023/1/93321_0s.jpg)
Android IPC机制绑定Service实现本地通信
2023-10-08 15:25:40
![](https://img.aspxhome.com/file/2023/9/137579_0s.png)
SpringBoot数据访问自定义使用Druid数据源的方法
2023-01-10 16:29:38
![](https://img.aspxhome.com/file/2023/1/91081_0s.jpg)
C#实体类转换的两种方式小结
2023-08-01 21:06:45
C#关于System.Collections空间详解
2022-04-12 16:04:06
Java编程中使用throw关键字抛出异常的用法简介
2023-08-27 17:04:19
![](https://img.aspxhome.com/file/2023/9/58209_0s.png)
一篇文章带你入门Java之编程规范
2022-02-25 16:18:40
![](https://img.aspxhome.com/file/2023/7/132087_0s.png)