Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions msclub-file-starter/pom.xml
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用这个模块了吗

<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>
13 changes: 13 additions & 0 deletions msclub-file-starter/src/main/java/com/msclub/base/file/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.msclub.base.file;

/**
* Hello world!
*
*/
public class App
Copy link
Contributor

Choose a reason for hiding this comment

The 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 = "";
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 );
}
}