pom.xml
<!-- docx4j -->
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j</artifactId>
<version>3.1.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- poi-->
<dependency>
<groupId>xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.poi</groupId>
<artifactId>poi-3.15-beta2.jar</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.poi</groupId>
<artifactId>poi-ooxml-3.15-beta2.jar</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.poi</groupId>
<artifactId>poi-ooxml-schemas-3.15-beta2.jar</artifactId>
<version>1.0</version>
</dependency>
<!-- docx4j -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>
</dependency>
----------
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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-web</artifactId>
</dependency>
<!--thymleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency><dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<!-- docx4j --><dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j</artifactId>
<version>3.1.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
</exclusion>
</exclusions>
</dependency><!-- poi-->
<dependency>
<groupId>xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.poi</groupId>
<artifactId>poi-3.15-beta2.jar</artifactId>
<version>1.0</version>
</dependency><dependency>
<groupId>com.poi</groupId>
<artifactId>poi-ooxml-3.15-beta2.jar</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.poi</groupId>
<artifactId>poi-ooxml-schemas-3.15-beta2.jar</artifactId>
<version>1.0</version>
</dependency><!-- docx4j -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>
</dependency>
FileUtil.java
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.springframework.web.multipart.MultipartFile;
/**
* 文件工具类
*
* @ClassName: FileUtil
* @Description: TODO(这里用一句话描述这个类的作用)
* @author wcl
* @date 2016年9月26日21:22:583
*
*/
public final class FileUtil {
/**
* 文件保存
*
* @param file
* 文件
* @param path
* 文件保存路径
* @param newName
* 新文件名
* @return
* @throws IOException
*/
public static String fileUpload(MultipartFile file, String path, String newName) throws IOException {
if (!file.isEmpty()) {
String filename = file.getOriginalFilename(); // 得到上传时的文件名
filename = newName + filename.substring(filename.lastIndexOf("."));
// 文件保存路径(images/用户编号/head/图片名)
String dir = path + "/"; // 设定文件保存的目录
FileUtils.writeByteArrayToFile(new File(dir, filename