-
Notifications
You must be signed in to change notification settings - Fork 6
new msclub-file-starter #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <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> | ||
|
|
||
| <artifactId>msclub-file-starter</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>msclub-file-starter</name> | ||
| <url>http://maven.apache.org</url> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>3.8.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| <parent> | ||
| <groupId>com.msclub.base</groupId> | ||
| <artifactId>msclub-parent</artifactId> | ||
| <version>0.0.1</version> | ||
| </parent> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.msclub.base.file; | ||
|
|
||
| /** | ||
| * Hello world! | ||
| * | ||
| */ | ||
| public class App | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果是测试用 请写到test目录中 |
||
| { | ||
| public static void main( String[] args ) | ||
| { | ||
| System.out.println( "Hello World!" ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.msclub.base.file; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileOutputStream; | ||
|
|
||
| import org.springframework.stereotype.Controller; | ||
|
|
||
| @Controller | ||
| public class FileUpload { | ||
| private static String pilePath = ""; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 禁止使用全局变量 |
||
|
|
||
|
|
||
|
|
||
| public FileUpload(String pilePath) { | ||
| super(); | ||
| this.pilePath = pilePath; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| public static void uploadFile(byte[] file, String fileName) throws Exception { | ||
| File targetFile = new File(pilePath); | ||
| if(!targetFile.exists()){ | ||
| targetFile.mkdirs(); | ||
| } | ||
| FileOutputStream out = new FileOutputStream(pilePath+fileName); | ||
| out.write(file); | ||
| out.flush(); | ||
| out.close(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.msclub.base.file; | ||
|
|
||
| import org.apache.http.client.HttpClient; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| /** | ||
| * Provides a {@link org.springframework.web.client.RestTemplate} configured with | ||
| * a pooled {@link HttpClient} suitable to perform better on an enterprise environment. | ||
| */ | ||
| @Configuration | ||
| public class FileUploadingAutoConfiguration { | ||
|
|
||
| @Autowired | ||
| private FileUploadingProperties fileUploadingProperties; | ||
|
|
||
| @Bean | ||
| public FileUpload fileUpload(String filePath) { | ||
| return new FileUpload(fileUploadingProperties.getFilePath()); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.msclub.base.file; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| @ConfigurationProperties(FileUploadingProperties.PREFIX) | ||
| public class FileUploadingProperties { | ||
| public static final String PREFIX = "msclub.fileuploadingConfig"; | ||
|
|
||
| private String filePath = ""; | ||
|
|
||
| public static String getPREFIX() { | ||
| return PREFIX; | ||
| } | ||
|
|
||
| public String getFilePath() { | ||
| return filePath; | ||
| } | ||
|
|
||
| public void setFilePath(String filePath) { | ||
| this.filePath = filePath; | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
| com.msclub.base.file.FileUploadingAutoConfiguration |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.msclub.base.file; | ||
|
|
||
| import junit.framework.Test; | ||
| import junit.framework.TestCase; | ||
| import junit.framework.TestSuite; | ||
|
|
||
| /** | ||
| * Unit test for simple App. | ||
| */ | ||
| public class AppTest | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里并不包括主要的上传逻辑的测试 |
||
| extends TestCase | ||
| { | ||
| /** | ||
| * Create the test case | ||
| * | ||
| * @param testName name of the test case | ||
| */ | ||
| public AppTest( String testName ) | ||
| { | ||
| super( testName ); | ||
| } | ||
|
|
||
| /** | ||
| * @return the suite of tests being tested | ||
| */ | ||
| public static Test suite() | ||
| { | ||
| return new TestSuite( AppTest.class ); | ||
| } | ||
|
|
||
| /** | ||
| * Rigourous Test :-) | ||
| */ | ||
| public void testApp() | ||
| { | ||
| assertTrue( true ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用这个模块了吗