## 静态资源访问路径 spring.mvc.static-path-pattern=/** ## 静态资源映射路径 spring.resources.static-locations=classpa
时间: 2025-01-25 08:08:42 浏览: 78
在Spring Boot应用中,静态资源(如CSS、JavaScript、图片等)的访问路径和映射路径可以通过配置文件进行设置。以下是对这两个配置项的详细介绍:
### 静态资源访问路径
```properties
spring.mvc.static-path-pattern=/**
```
这个配置项指定了访问静态资源的URL模式。默认值是`/**`,这意味着所有的静态资源都可以通过根路径直接访问。例如,`http://localhost:8080/css/style.css`可以直接访问`src/main/resources/static/css/style.css`。
### 静态资源映射路径
```properties
spring.resources.static-locations=classpath:/static/,classpath:/public/,classpath:/resources/,classpath:/META-INF/resources/
```
这个配置项指定了静态资源的存放位置。默认情况下,Spring Boot会在以下目录中查找静态资源:
- `classpath:/resources/`
- `classpath:/META-INF/resources/`
这些目录中的资源可以通过上面配置的访问路径直接访问。
### 示例
假设有以下目录结构:
```
src/main/resources/
static/
css/
style.css
js/
app.js
public/
images/
logo.png
```
- `style.css`可以通过`http://localhost:8080/css/style.css`访问。
- `app.js`可以通过`http://localhost:8080/js/app.js`访问。
- `logo.png`可以通过`http://localhost:8080/images/logo.png`访问。
通过这些配置,开发者可以灵活地管理静态资源的位置和访问方式。
阅读全文
相关推荐














<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="zh-CN" class="bootstrap-admin-vertical-centered">
<head>
<meta charset="UTF-8">
<title>图书馆管理系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="static/js/bootstrap.min.js"></script>
<script src="static/jQuery/jquery-3.1.1.min.js"></script>
<script src="static/ajax-lib/ajaxutils.js"></script>
<script src="static/js/login.js"></script>
</head>
<style type="text/css">
.alert{
margin: 0 auto 20px;
text-align: center;
}
</style>
<script src="static/js/jquery.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<body class="bootstrap-admin-without-padding">
池州学院 230312242 杨洪博 课设
×
欢迎登录图书馆管理系统
<form class="bootstrap-admin-login-form" method="post" action="/https/wenku.csdn.net/books/LoginServlet">
<%
String state = (String)session.getAttribute("state");
session.removeAttribute("state");
if(state!=null){
%>
<label class="control-label" for="username">密码错误</label>
<%}%>
<label class="control-label" for="username">账 号</label>
<input type="text" class="form-control" id="username" name="username" required="required" placeholder="学号"/>
<label class="control-label" for="username" style="display:none;"></label>
<label class="control-label" for="password">密 码</label>
<input type="password" class="form-control" id="password" name="password" required="required" placeholder="密码"/>
<label class="control-label" for="username" style="display:none;"></label>
<label class="control-label" for="password">没有账号请注册</label>
<input type="submit" class="btn btn-lg btn-primary" value="登 录"/>
</form>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
提示
<button type="button" class="btn btn-default" id="btn_info_close" data-dismiss="modal">关闭</button>
</body>
</html> 图片不显示 是哪里出了问题




