Skip to content

Commit b29e410

Browse files
committed
【修改】增加文件上传接口
1 parent 01e5787 commit b29e410

File tree

6 files changed

+319
-170
lines changed

6 files changed

+319
-170
lines changed

pom.xml

Lines changed: 176 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -1,188 +1,194 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<parent>
6-
<groupId>org.springframework.boot</groupId>
7-
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.1.6.RELEASE</version>
9-
<relativePath/> <!-- lookup parent from repository -->
10-
</parent>
11-
<groupId>com.shellming</groupId>
12-
<artifactId>ele-service</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
14-
<name>ele-service</name>
15-
<description>Demo project for Spring Boot</description>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.1.6.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.shellming</groupId>
12+
<artifactId>ele-service</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>ele-service</name>
15+
<description>Demo project for Spring Boot</description>
1616

17-
<properties>
18-
<java.version>1.8</java.version>
19-
</properties>
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
2020

21-
<dependencies>
22-
<dependency>
23-
<groupId>org.springframework.boot</groupId>
24-
<artifactId>spring-boot-configuration-processor</artifactId>
25-
<optional>true</optional>
26-
</dependency>
27-
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
28-
<dependency>
29-
<groupId>mysql</groupId>
30-
<artifactId>mysql-connector-java</artifactId>
31-
<version>5.1.47</version>
32-
</dependency>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-configuration-processor</artifactId>
25+
<optional>true</optional>
26+
</dependency>
27+
<!-- 文件上传-->
28+
<dependency>
29+
<groupId>commons-fileupload</groupId>
30+
<artifactId>commons-fileupload</artifactId>
31+
<version>1.3.3</version>
32+
</dependency>
33+
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
34+
<dependency>
35+
<groupId>mysql</groupId>
36+
<artifactId>mysql-connector-java</artifactId>
37+
<version>5.1.47</version>
38+
</dependency>
3339

34-
<!--mybatis.generator-->
35-
<dependency>
36-
<groupId>org.mybatis.generator</groupId>
37-
<artifactId>mybatis-generator-core</artifactId>
38-
<version>1.3.5</version>
39-
</dependency>
40+
<!--mybatis.generator-->
41+
<dependency>
42+
<groupId>org.mybatis.generator</groupId>
43+
<artifactId>mybatis-generator-core</artifactId>
44+
<version>1.3.5</version>
45+
</dependency>
4046

41-
<!-- swagger -->
42-
<dependency>
43-
<groupId>io.springfox</groupId>
44-
<artifactId>springfox-swagger2</artifactId>
45-
<version>2.5.0</version>
46-
</dependency>
47-
<!-- swagger-ui -->
48-
<dependency>
49-
<groupId>io.springfox</groupId>
50-
<artifactId>springfox-swagger-ui</artifactId>
51-
<version>2.5.0</version>
52-
</dependency>
47+
<!-- swagger -->
48+
<dependency>
49+
<groupId>io.springfox</groupId>
50+
<artifactId>springfox-swagger2</artifactId>
51+
<version>2.5.0</version>
52+
</dependency>
53+
<!-- swagger-ui -->
54+
<dependency>
55+
<groupId>io.springfox</groupId>
56+
<artifactId>springfox-swagger-ui</artifactId>
57+
<version>2.5.0</version>
58+
</dependency>
5359

54-
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
55-
<dependency>
56-
<groupId>org.apache.commons</groupId>
57-
<artifactId>commons-lang3</artifactId>
58-
<version>3.9</version>
59-
</dependency>
60+
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
61+
<dependency>
62+
<groupId>org.apache.commons</groupId>
63+
<artifactId>commons-lang3</artifactId>
64+
<version>3.9</version>
65+
</dependency>
6066

61-
<!-- 分页 -->
67+
<!-- 分页 -->
6268
<dependency>
6369
<groupId>com.github.pagehelper</groupId>
6470
<artifactId>pagehelper</artifactId>
6571
<version>5.1.2</version>
6672
</dependency>
67-
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-autoconfigure -->
68-
<dependency>
69-
<groupId>com.github.pagehelper</groupId>
70-
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
71-
<version>1.2.3</version>
72-
</dependency>
73+
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-autoconfigure -->
74+
<dependency>
75+
<groupId>com.github.pagehelper</groupId>
76+
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
77+
<version>1.2.3</version>
78+
</dependency>
7379

74-
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
75-
<dependency>
76-
<groupId>com.github.pagehelper</groupId>
77-
<artifactId>pagehelper-spring-boot-starter</artifactId>
78-
<version>1.2.3</version>
79-
</dependency>
80-
<!--JWT-->
81-
<dependency>
82-
<groupId>io.jsonwebtoken</groupId>
83-
<artifactId>jjwt</artifactId>
84-
<version>0.9.0</version>
85-
</dependency>
86-
<!--Redis-->
87-
<dependency>
88-
<groupId>org.springframework.boot</groupId>
89-
<artifactId>spring-boot-starter-data-redis</artifactId>
90-
</dependency>
91-
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
92-
<dependency>
93-
<groupId>org.apache.commons</groupId>
94-
<artifactId>commons-pool2</artifactId>
95-
<version>2.6.2</version>
96-
</dependency>
97-
<!-- https://mvnrepository.com/artifact/commons-io/commons-io 文件工具类 -->
98-
<dependency>
99-
<groupId>commons-io</groupId>
100-
<artifactId>commons-io</artifactId>
101-
<version>2.6</version>
102-
</dependency>
103-
<!-- https://mvnrepository.com/artifact/net.sf.json-lib/json-lib -->
104-
<dependency>
105-
<groupId>net.sf.json-lib</groupId>
106-
<artifactId>json-lib</artifactId>
107-
<version>2.4</version>
108-
<classifier>jdk15</classifier>
109-
</dependency>
110-
<dependency>
111-
<groupId>com.alibaba</groupId>
112-
<artifactId>fastjson</artifactId>
113-
<version>1.2.49</version>
114-
</dependency>
115-
<dependency>
116-
<groupId>org.springframework.boot</groupId>
117-
<artifactId>spring-boot-starter-web</artifactId>
118-
</dependency>
119-
<dependency>
120-
<groupId>org.mybatis.spring.boot</groupId>
121-
<artifactId>mybatis-spring-boot-starter</artifactId>
122-
<version>2.0.1</version>
123-
</dependency>
80+
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
81+
<dependency>
82+
<groupId>com.github.pagehelper</groupId>
83+
<artifactId>pagehelper-spring-boot-starter</artifactId>
84+
<version>1.2.3</version>
85+
</dependency>
86+
<!--JWT-->
87+
<dependency>
88+
<groupId>io.jsonwebtoken</groupId>
89+
<artifactId>jjwt</artifactId>
90+
<version>0.9.0</version>
91+
</dependency>
92+
<!--Redis-->
93+
<dependency>
94+
<groupId>org.springframework.boot</groupId>
95+
<artifactId>spring-boot-starter-data-redis</artifactId>
96+
</dependency>
97+
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
98+
<dependency>
99+
<groupId>org.apache.commons</groupId>
100+
<artifactId>commons-pool2</artifactId>
101+
<version>2.6.2</version>
102+
</dependency>
103+
<!-- https://mvnrepository.com/artifact/commons-io/commons-io 文件工具类 -->
104+
<dependency>
105+
<groupId>commons-io</groupId>
106+
<artifactId>commons-io</artifactId>
107+
<version>2.6</version>
108+
</dependency>
109+
<!-- https://mvnrepository.com/artifact/net.sf.json-lib/json-lib -->
110+
<dependency>
111+
<groupId>net.sf.json-lib</groupId>
112+
<artifactId>json-lib</artifactId>
113+
<version>2.4</version>
114+
<classifier>jdk15</classifier>
115+
</dependency>
116+
<dependency>
117+
<groupId>com.alibaba</groupId>
118+
<artifactId>fastjson</artifactId>
119+
<version>1.2.49</version>
120+
</dependency>
121+
<dependency>
122+
<groupId>org.springframework.boot</groupId>
123+
<artifactId>spring-boot-starter-web</artifactId>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.mybatis.spring.boot</groupId>
127+
<artifactId>mybatis-spring-boot-starter</artifactId>
128+
<version>2.0.1</version>
129+
</dependency>
124130

125-
<dependency>
126-
<groupId>org.springframework.boot</groupId>
127-
<artifactId>spring-boot-devtools</artifactId>
128-
<scope>runtime</scope>
129-
<optional>true</optional>
130-
</dependency>
131-
<dependency>
132-
<groupId>org.projectlombok</groupId>
133-
<artifactId>lombok</artifactId>
134-
<optional>true</optional>
135-
</dependency>
136-
<dependency>
137-
<groupId>org.springframework.boot</groupId>
138-
<artifactId>spring-boot-starter-test</artifactId>
139-
<scope>test</scope>
140-
</dependency>
141-
<dependency>
142-
<groupId>org.springframework.boot</groupId>
143-
<artifactId>spring-boot-starter-data-jpa</artifactId>
144-
</dependency>
145-
<dependency>
146-
<groupId>org.springframework.boot</groupId>
147-
<artifactId>spring-boot-starter-data-jpa</artifactId>
148-
</dependency>
149-
</dependencies>
131+
<dependency>
132+
<groupId>org.springframework.boot</groupId>
133+
<artifactId>spring-boot-devtools</artifactId>
134+
<scope>runtime</scope>
135+
<optional>true</optional>
136+
</dependency>
137+
<dependency>
138+
<groupId>org.projectlombok</groupId>
139+
<artifactId>lombok</artifactId>
140+
<optional>true</optional>
141+
</dependency>
142+
<dependency>
143+
<groupId>org.springframework.boot</groupId>
144+
<artifactId>spring-boot-starter-test</artifactId>
145+
<scope>test</scope>
146+
</dependency>
147+
<dependency>
148+
<groupId>org.springframework.boot</groupId>
149+
<artifactId>spring-boot-starter-data-jpa</artifactId>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.springframework.boot</groupId>
153+
<artifactId>spring-boot-starter-data-jpa</artifactId>
154+
</dependency>
155+
</dependencies>
150156

151-
<build>
152-
<plugins>
153-
<plugin>
154-
<groupId>org.springframework.boot</groupId>
155-
<artifactId>spring-boot-maven-plugin</artifactId>
156-
</plugin>
157-
</plugins>
158-
<resources>
159-
<resource>
160-
<directory>src/main/java</directory>
161-
<includes>
162-
<include>**/*.yml</include>
163-
<include>**/*.properties</include>
164-
<include>**/*.xml</include>
165-
<include>**/*.json</include>
166-
</includes>
167-
<filtering>false</filtering>
168-
</resource>
169-
<resource>
170-
<directory>src/main/resources</directory>
171-
<includes>
172-
<include>**/*.yml</include>
173-
<include>**/*.properties</include>
174-
<include>**/*.json</include>
175-
<include>**/*.xml</include>
176-
</includes>
177-
<filtering>false</filtering>
178-
</resource>
179-
</resources>
180-
</build>
157+
<build>
158+
<plugins>
159+
<plugin>
160+
<groupId>org.springframework.boot</groupId>
161+
<artifactId>spring-boot-maven-plugin</artifactId>
162+
</plugin>
163+
</plugins>
164+
<resources>
165+
<resource>
166+
<directory>src/main/java</directory>
167+
<includes>
168+
<include>**/*.yml</include>
169+
<include>**/*.properties</include>
170+
<include>**/*.xml</include>
171+
<include>**/*.json</include>
172+
</includes>
173+
<filtering>false</filtering>
174+
</resource>
175+
<resource>
176+
<directory>src/main/resources</directory>
177+
<includes>
178+
<include>**/*.yml</include>
179+
<include>**/*.properties</include>
180+
<include>**/*.json</include>
181+
<include>**/*.xml</include>
182+
</includes>
183+
<filtering>false</filtering>
184+
</resource>
185+
</resources>
186+
</build>
181187

182-
<repositories>
183-
<repository>
184-
<id>aliyunmaven</id>
185-
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
186-
</repository>
187-
</repositories>
188+
<repositories>
189+
<repository>
190+
<id>aliyunmaven</id>
191+
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
192+
</repository>
193+
</repositories>
188194
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.shellming.eleservice.config;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
6+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7+
8+
/**
9+
* * 设置虚拟路径,访问绝对路径下资源
10+
*/
11+
@Configuration
12+
public class UploadFilePathConfig implements WebMvcConfigurer {
13+
14+
@Value("${file.staticAccessPath}")
15+
private String staticAccessPath;
16+
17+
@Value("${file.uploadFolder}")
18+
private String uploadFolder;
19+
20+
@Override
21+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
22+
registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder);
23+
}
24+
25+
}

0 commit comments

Comments
 (0)