This repository was archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
增加java服务器端demo #2805
Open
Open
增加java服务器端demo #2805
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
server/java-spring/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.zts</groupId> | ||
<artifactId>webuploader-server</artifactId> | ||
<packaging>pom</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<modules> | ||
<module>webuploader-server-lib</module> | ||
<module>webuploader-server-webdemo</module> | ||
</modules> | ||
|
||
<properties> | ||
<spring.version>5.0.5.RELEASE</spring.version> | ||
<slf4j.version>1.7.24</slf4j.version> | ||
<log4j.version>2.8.2</log4j.version> | ||
<thymeleaf.version>3.0.7.RELEASE</thymeleaf.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<!-- spring framework start --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>${spring.version}</version> | ||
|
||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<version>${spring.version}</version> | ||
|
||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-beans</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context-support</artifactId> | ||
<version>${spring.version}</version> | ||
|
||
</dependency> | ||
<!-- spring framework end --> | ||
|
||
|
||
<!-- --> | ||
<dependency> | ||
<groupId>commons-fileupload</groupId> | ||
<artifactId>commons-fileupload</artifactId> | ||
<version>1.3.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<version>2.9.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.9.1</version> | ||
</dependency> | ||
|
||
<!-- test start --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- test end --> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!--lambok--> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.16.20</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
44 changes: 44 additions & 0 deletions
server/java-spring/webuploader-server-lib/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>webuploader-server</artifactId> | ||
<groupId>io.zts</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>jar</packaging> | ||
|
||
<artifactId>webuploader-server-lib</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-fileupload</groupId> | ||
<artifactId>commons-fileupload</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
80 changes: 80 additions & 0 deletions
...-spring/webuploader-server-lib/src/main/java/io/zts/controller/WebuploaderController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.zts.controller; | ||
|
||
import io.zts.controller.vo.CheckResponse; | ||
import io.zts.controller.vo.MergeResponse; | ||
import io.zts.controller.vo.UploadResponse; | ||
import io.zts.controller.vo.WebuploaderResponse; | ||
import io.zts.webuploader.service.WebuploaderService; | ||
import io.zts.webuploader.service.enums.MergeResult; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.commons.CommonsMultipartFile; | ||
|
||
import java.io.IOException; | ||
|
||
@RestController | ||
@RequestMapping("/webuploader") | ||
@Slf4j | ||
public class WebuploaderController { | ||
|
||
@Autowired | ||
private WebuploaderService uploadService; | ||
|
||
|
||
@RequestMapping(value = "/check",produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||
public WebuploaderResponse<CheckResponse> checkChunk( | ||
@RequestParam(name = "fileName") String filename, | ||
@RequestParam(name="fileMd5",required = false) String fileMd5, | ||
@RequestParam(name="chunkSize") long chunkSize, | ||
@RequestParam(name="chunk") int chunkNum | ||
){ | ||
boolean checkResult = this.uploadService.checkChunk(filename, chunkNum, chunkSize, fileMd5); | ||
|
||
CheckResponse bizResponse=new CheckResponse(); | ||
bizResponse.setExists(checkResult); | ||
return WebuploaderResponse.SUCC(bizResponse); | ||
} | ||
|
||
@RequestMapping(value = "/upload",produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||
public WebuploaderResponse<UploadResponse> uploadChunk( | ||
@RequestParam("file") CommonsMultipartFile file, | ||
@RequestParam(value = "name") String fileName, | ||
@RequestParam(value = "chunk", required = false, defaultValue = "0") int chunk, | ||
@RequestParam("fileMd5") String fileMd5){ | ||
|
||
UploadResponse bizResponse=new UploadResponse(); | ||
try { | ||
this.uploadService.saveOneChunk(fileName,file,chunk,fileMd5); | ||
bizResponse.setUploaded(true); | ||
return WebuploaderResponse.SUCC(bizResponse); | ||
} catch (Exception e) { | ||
log.error("",e); | ||
bizResponse.setUploaded(false); | ||
return WebuploaderResponse.FAIL(bizResponse); | ||
} | ||
|
||
|
||
} | ||
|
||
@RequestMapping(value = "/merge",produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||
public WebuploaderResponse<MergeResponse> mergeChunks( | ||
@RequestParam(name = "fileName") String filename, | ||
@RequestParam(name="fileMd5",required = false) String fileMd5, | ||
@RequestParam(name="chunks") int chunk){ | ||
|
||
MergeResponse bizResponse=new MergeResponse(); | ||
bizResponse.setFileName(filename); | ||
MergeResult result = this.uploadService.mergeChunks(filename, chunk, fileMd5, bizResponse); | ||
if(result==MergeResult.SUCCESS){ | ||
|
||
return WebuploaderResponse.SUCC(bizResponse); | ||
} | ||
|
||
log.error("Merge Result={}",result); | ||
return WebuploaderResponse.FAIL(bizResponse); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
.../java-spring/webuploader-server-lib/src/main/java/io/zts/controller/vo/CheckResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.zts.controller.vo; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
|
||
@Setter | ||
@Getter | ||
@JsonInclude(value=JsonInclude.Include.NON_EMPTY) | ||
|
||
public class CheckResponse implements Serializable { | ||
|
||
private boolean isExists; | ||
} |
17 changes: 17 additions & 0 deletions
.../java-spring/webuploader-server-lib/src/main/java/io/zts/controller/vo/MergeResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.zts.controller.vo; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
|
||
@Getter | ||
@Setter | ||
@JsonInclude(value=JsonInclude.Include.NON_EMPTY) | ||
public class MergeResponse implements Serializable { | ||
|
||
private String fileName; | ||
private String finalName; | ||
private String path; | ||
} |
15 changes: 15 additions & 0 deletions
...java-spring/webuploader-server-lib/src/main/java/io/zts/controller/vo/UploadResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.zts.controller.vo; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
|
||
@Setter | ||
@Getter | ||
@JsonInclude(value=JsonInclude.Include.NON_EMPTY) | ||
public class UploadResponse implements Serializable { | ||
|
||
private boolean uploaded; | ||
} |
28 changes: 28 additions & 0 deletions
...spring/webuploader-server-lib/src/main/java/io/zts/controller/vo/WebuploaderResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.zts.controller.vo; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
|
||
@Setter | ||
@Getter | ||
public class WebuploaderResponse<T extends Serializable> implements Serializable { | ||
|
||
private T content; | ||
|
||
private int code; | ||
|
||
public static WebuploaderResponse SUCC(Serializable content){ | ||
WebuploaderResponse response=new WebuploaderResponse(); | ||
response.setContent(content); | ||
response.setCode(0); | ||
return response; | ||
} | ||
|
||
public static WebuploaderResponse FAIL(Serializable content){ | ||
WebuploaderResponse response=SUCC(content); | ||
response.setCode(-1); | ||
return response; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
...pring/webuploader-server-lib/src/main/java/io/zts/webuploader/config/ConfigException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.zts.webuploader.config; | ||
|
||
/** | ||
* 配置异常 | ||
*/ | ||
public class ConfigException extends RuntimeException { | ||
|
||
public ConfigException (String msg){ | ||
super(msg); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
...ing/webuploader-server-lib/src/main/java/io/zts/webuploader/config/WebuploaderConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.zts.webuploader.config; | ||
|
||
/** | ||
* Webuploader 配置接口 | ||
*/ | ||
public interface WebuploaderConfig { | ||
|
||
/** | ||
* 临时文件存储目录 | ||
* @return | ||
*/ | ||
public String getTempDir(); | ||
|
||
/** | ||
* 上传文件目录 | ||
* @return | ||
*/ | ||
public String getUploaderDir(); | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.