Skip to content

Commit f5609ae

Browse files
1.2.1-RELEASE 上传下载,静态资源访问 💥
Former-commit-id: bf2833f2b2a8fe4a27a1c3ae23b3677f51711e49
1 parent deca864 commit f5609ae

File tree

17 files changed

+451
-16
lines changed

17 files changed

+451
-16
lines changed

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
# 更新日志 CHANGELOG
22

3+
## [V1.2.1-RELEASE] 2019.08.20
4+
5+
### ⚡️ Optimization
6+
- 启用项目静态资源访问,可访问static/templates目录下资源
7+
- static资源访问:http://127.0.0.1:8888/static/welcome.html
8+
- templates资源访问:http://127.0.0.1:8888/templates/springbootplus.html
9+
10+
### ⭐️ New Features
11+
- 文件上传保存到服务器指定目录
12+
- 文件下载
13+
- 访问上传的图片等资源
14+
- static/templates项目静态资源访问
15+
16+
### 📝 Added/Modified
17+
- Add `UploadController` 上传控制器
18+
- Add `DownloadController` 下载控制器
19+
- Add `ImageController` 图片访问控制器
20+
- Add `ResourceInterceptor` 资源拦截器
21+
22+
- Modify `WebMvcConfig` 注册资源拦截器,项目静态资源访问配置
23+
- Modify `SpringBootPlusConfig` 创建 `ResourceInterceptor` 资源拦截器
24+
- Modify `SpringBootPlusInterceptorConfig` 添加 `resourceConfig` 资源拦截器配置
25+
- Modify `SpringBootPlusProperties` 添加 `uploadPath`,`resourceAccessPath`,`resourceAccessPatterns`,`resourceAccessUrl`属性
26+
- Modify `application.yml`, `application-local.yml` 添加文件上传/下载配置
27+
28+
- Modify `mysql_spring_boot_plus.sql` 添加创建数据库语句,如果不存在,则创建
29+
30+
31+
### 🔨 Dependency Upgrades
32+
- Upgrade to springboot 2.1.7.RELEASE
33+
34+
35+
336
## [V1.2.0-RELEASE] 2019.08.06
437
### 🚀 spring-boot-plus演示地址
538
- 👉 [spring-boot-plus演示地址-Spring Boot Admin](http://47.105.159.10:8888)

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ Redis | 3.2+ | |
5858
### 技术选型
5959
技术 | 版本 | 备注
6060
-|-|-
61-
Spring Boot | 2.1.6.RELEASE | 最新发布稳定版 |
62-
Spring Framework | 5.1.8.RELEASE | 最新发布稳定版 |
61+
Spring Boot | 2.1.7.RELEASE | 最新发布稳定版 |
62+
Spring Framework | 5.1.9.RELEASE | 最新发布稳定版 |
6363
Mybatis | 3.5.1 | 持久层框架 |
64-
Mybatis Plus | 3.1.1 | mybatis增强框架 |
65-
Alibaba Druid | 1.1.17 | 数据源 |
66-
Fastjson | 1.2.58 | JSON处理工具集 |
64+
Mybatis Plus | 3.1.2 | mybatis增强框架 |
65+
Alibaba Druid | 1.1.18 | 数据源 |
66+
Fastjson | 1.2.59 | JSON处理工具集 |
6767
swagger2 | 2.6.1 | api文档生成工具 |
6868
commons-lang3 | 3.9 | 常用工具包 |
6969
commons-io | 2.6 | IO工具包 |

docs/db/mysql_spring_boot_plus.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
-- ----------------------------
18+
-- Create Database for spring_boot_plus
19+
-- ----------------------------
20+
create database if not exists spring_boot_plus character set utf8mb4;
21+
1722
-- ----------------------------
1823
-- Table structure for ip
1924
-- ----------------------------

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<groupId>io.geekidea</groupId>
2323
<artifactId>spring-boot-plus</artifactId>
24-
<version>1.2.0.RELEASE</version>
24+
<version>1.2.1.RELEASE</version>
2525
<packaging>jar</packaging>
2626

2727
<name>spring-boot-plus</name>
@@ -46,7 +46,7 @@
4646
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
4747
<project-parent.version>${parent.version}</project-parent.version>
4848
<java.version>1.8</java.version>
49-
<spring-boot.version>2.1.6.RELEASE</spring-boot.version>
49+
<spring-boot.version>2.1.7.RELEASE</spring-boot.version>
5050
<mybatis-plus-boot-starter.version>3.1.2</mybatis-plus-boot-starter.version>
5151
<fastjson.version>1.2.59</fastjson.version>
5252
<swagger2.version>2.6.1</swagger2.version>

src/main/assembly/assembly.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
<!-- 打包的类型,如果有N个,将会打N个类型的包 -->
2424
<formats>
25-
<format>dir</format>
2625
<format>tar.gz</format>
2726
<format>zip</format>
2827
</formats>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.geekidea.springbootplus.common.web.interceptor;
18+
19+
import lombok.extern.slf4j.Slf4j;
20+
import org.springframework.web.method.HandlerMethod;
21+
import org.springframework.web.servlet.ModelAndView;
22+
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
23+
24+
import javax.servlet.http.HttpServletRequest;
25+
import javax.servlet.http.HttpServletResponse;
26+
27+
/**
28+
* 资源拦截器
29+
* @author geekidea
30+
* @date 2019/8/20
31+
* @since 1.2.1-RELEASE
32+
*/
33+
@Slf4j
34+
public class ResourceInterceptor extends HandlerInterceptorAdapter {
35+
36+
@Override
37+
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
38+
// 如果访问的控制器,则跳出,继续执行下一个拦截器
39+
if (handler instanceof HandlerMethod) {
40+
return true;
41+
}
42+
// 资源拦截器,业务处理代码
43+
log.info("ResourceInterceptor...");
44+
// 访问路径
45+
String url = request.getRequestURI();
46+
// 访问全路径
47+
String fullUrl = request.getRequestURL().toString();
48+
// 访问token,如果需要,可以设置参数,进行鉴权
49+
String token = request.getParameter("token");
50+
51+
log.info("url:{}",url);
52+
log.info("fullUrl:{}",fullUrl);
53+
log.info("token:{}",token);
54+
55+
return true;
56+
}
57+
58+
@Override
59+
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
60+
// 记录实际访问图片日志...
61+
}
62+
}

src/main/java/io/geekidea/springbootplus/config/WebMvcConfig.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.geekidea.springbootplus.config;
1818

1919
import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor;
20+
import io.geekidea.springbootplus.common.web.interceptor.ResourceInterceptor;
2021
import io.geekidea.springbootplus.common.web.interceptor.TokenTimeoutInterceptor;
2122
import io.geekidea.springbootplus.config.core.SpringBootPlusProperties;
2223
import io.geekidea.springbootplus.security.interceptor.JwtInterceptor;
@@ -47,20 +48,26 @@ public class WebMvcConfig implements WebMvcConfigurer {
4748
@Autowired
4849
private TokenTimeoutInterceptor tokenTimeoutInterceptor;
4950

51+
@Autowired
52+
private ResourceInterceptor resourceInterceptor;
53+
5054
@Override
5155
public void addInterceptors(InterceptorRegistry registry) {
56+
// 资源拦截器注册
57+
registry.addInterceptor(resourceInterceptor)
58+
.addPathPatterns(springBootPlusProperties.getInterceptorConfig().getResourceConfig().getIncludePath());
5259

53-
// // JWT拦截器
60+
// // JWT拦截器注册
5461
// registry.addInterceptor(jwtInterceptor)
5562
// .addPathPatterns("/**")
5663
// .excludePathPatterns(springBootPlusProperties.getInterceptorConfig().getJwtConfig().getExcludePath());
5764
//
58-
// // TOKEN超时拦截器
65+
// // TOKEN超时拦截器注册
5966
// registry.addInterceptor(tokenTimeoutInterceptor)
6067
// .addPathPatterns("/**")
6168
// .excludePathPatterns(springBootPlusProperties.getInterceptorConfig().getTokenTimeoutConfig().getExcludePath());
6269
//
63-
// // 权限拦截器
70+
// // 权限拦截器注册
6471
// registry.addInterceptor(permissionInterceptor)
6572
// .addPathPatterns("/**")
6673
// .excludePathPatterns(springBootPlusProperties.getInterceptorConfig().getPermissionConfig().getExcludePath());
@@ -69,9 +76,18 @@ public void addInterceptors(InterceptorRegistry registry) {
6976

7077
@Override
7178
public void addResourceHandlers(ResourceHandlerRegistry registry) {
79+
// 设置项目静态资源访问
80+
registry.addResourceHandler("/static/**")
81+
.addResourceLocations("classpath:/static/");
82+
registry.addResourceHandler("/templates/**")
83+
.addResourceLocations("classpath:/templates/");
84+
// 设置swagger静态资源访问
7285
registry.addResourceHandler("swagger-ui.html")
7386
.addResourceLocations("classpath:/META-INF/resources/");
7487
registry.addResourceHandler("/webjars/**")
7588
.addResourceLocations("classpath:/META-INF/resources/webjars/");
89+
// 设置上传文件访问路径
90+
registry.addResourceHandler(springBootPlusProperties.getResourceAccessPatterns())
91+
.addResourceLocations("file:" + springBootPlusProperties.getUploadPath());
7692
}
7793
}

src/main/java/io/geekidea/springbootplus/config/core/SpringBootPlusConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import io.geekidea.springbootplus.common.aop.LogAop;
1919
import io.geekidea.springbootplus.common.web.interceptor.PermissionInterceptor;
20+
import io.geekidea.springbootplus.common.web.interceptor.ResourceInterceptor;
2021
import io.geekidea.springbootplus.common.web.interceptor.TokenTimeoutInterceptor;
2122
import io.geekidea.springbootplus.security.interceptor.JwtInterceptor;
2223
import lombok.extern.slf4j.Slf4j;
@@ -79,4 +80,14 @@ public TokenTimeoutInterceptor tokenTimeoutInterceptor(){
7980
return tokenTimeoutInterceptor;
8081
}
8182

83+
/**
84+
* 资源拦截器
85+
* @return
86+
*/
87+
@Bean
88+
public ResourceInterceptor resourceInterceptor(){
89+
ResourceInterceptor resourceInterceptor = new ResourceInterceptor();
90+
return resourceInterceptor;
91+
}
92+
8293
}

src/main/java/io/geekidea/springbootplus/config/core/SpringBootPlusInterceptorConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public class SpringBootPlusInterceptorConfig implements Serializable {
4545
*/
4646
private InterceptorConfig permissionConfig;
4747

48+
/**
49+
* 资源拦截器
50+
*/
51+
private InterceptorConfig resourceConfig;
52+
4853
@Data
4954
public static class InterceptorConfig {
5055

@@ -53,6 +58,11 @@ public static class InterceptorConfig {
5358
*/
5459
private String excludePath;
5560

61+
/**
62+
* 包含的路径
63+
*/
64+
private String includePath;
65+
5666
}
5767

5868
}

src/main/java/io/geekidea/springbootplus/config/core/SpringBootPlusProperties.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,22 @@ public class SpringBootPlusProperties {
5858
@NestedConfigurationProperty
5959
private SpringBootPlusInterceptorConfig interceptorConfig;
6060

61+
62+
/**
63+
* 上传目录
64+
*/
65+
private String uploadPath;
66+
/**
67+
* 资源访问路径,前端访问
68+
*/
69+
private String resourceAccessPath;
70+
/**
71+
* 资源访问路径,后段配置,资源映射/拦截器使用
72+
*/
73+
private String resourceAccessPatterns;
74+
/**
75+
* 资源访问全路径
76+
*/
77+
private String resourceAccessUrl;
78+
6179
}

0 commit comments

Comments
 (0)