Skip to content

Commit

Permalink
SpringBootLearning增加POI集成模块搭建
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangYinHua committed Aug 27, 2018
1 parent 7ed4ba2 commit 2a03e12
Show file tree
Hide file tree
Showing 15 changed files with 655 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SpringBoot-Mail/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>springboot-mail</artifactId>

<name>SpringBoot-Mail</name>
<description>SpringBoot整和Mail</description>
<description>SpringBoot整合Mail</description>

<parent>
<groupId>com.lance.learn</groupId>
Expand Down
2 changes: 1 addition & 1 deletion SpringBoot-Mybatis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<!--<scope>runtime</scope>-->
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
Empty file.
15 changes: 15 additions & 0 deletions SpringBoot-Mybatis/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#update port :8010
server:
address: 8010

spring:
#config mysql datasource
datasource:
url: jdbc:mysql://127.0.0.1:3306/lance?useUnicode=true&characterEncoding=utf8
username: root
password: 12345
driver-class-name: com.mysql.jdbc.Driver

#mybatis config
mybatis:
mapper-locations: classpath:mapper/*.xml
25 changes: 25 additions & 0 deletions SpringBoot-POI/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/target/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
78 changes: 78 additions & 0 deletions SpringBoot-POI/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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>
<artifactId>springboot-poi</artifactId>

<parent>
<groupId>com.lance.learn</groupId>
<artifactId>springbootlearning</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<name>springboot-poi</name>
<description>Demo project for Spring Boot</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!--<scope>runtime</scope>-->
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!--poi-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>SpringBoot-Mybatis-${profileActive}</finalName>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.lance.learn.springbootpoi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringbootPoiApplication {

public static void main(String[] args) {
SpringApplication.run(SpringbootPoiApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.lance.learn.springbootpoi.controller;

import com.lance.learn.springbootpoi.service.ExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
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.MultipartFile;

/**
* @Auther: Lance(ZYH)
* @Date: 2018/8/27 14:01
* @Description: 处理excel文件上传\下载
*/
@RestController
@RequestMapping("/excel")
public class ExcelController {

@Autowired
private ExcelService excelService;

@PostMapping("/upload")
public String uploadExcel(@RequestParam MultipartFile file){
String fileName = file.getOriginalFilename();
try {
excelService.uploadExcel(fileName,file);
} catch (Exception e) {
e.printStackTrace();
}
return "success";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.lance.learn.springbootpoi.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
* @Auther: Lance(ZYH)
* @Date: 2018/8/27 13:56
* @Description: User实体类
*/
public class User implements Serializable {
private Integer id;
private String name;
private String phone;
private String address;
private Date registerDate;
private String desc;

public User(Integer id, String name, String phone, String address, Date registerDate, String desc) {
this.id = id;
this.name = name;
this.phone = phone;
this.address = address;
this.registerDate = registerDate;
this.desc = desc;
}

public User() {
super();
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public Date getRegisterDate() {
return registerDate;
}

public void setRegisterDate(Date registerDate) {
this.registerDate = registerDate;
}

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return Objects.equals(id, user.id) &&
Objects.equals(name, user.name) &&
Objects.equals(phone, user.phone) &&
Objects.equals(address, user.address) &&
Objects.equals(registerDate, user.registerDate) &&
Objects.equals(desc, user.desc);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
result = prime * result + ((getAddress() == null) ? 0 : getAddress().hashCode());
result = prime * result + ((getRegisterDate() == null) ? 0 : getRegisterDate().hashCode());
result = prime * result + ((getDesc() == null) ? 0 : getDesc().hashCode());
return result;
}

@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", phone='" + phone + '\'' +
", address='" + address + '\'' +
", registerDate=" + registerDate +
", desc='" + desc + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.lance.learn.springbootpoi.service;

import org.springframework.web.multipart.MultipartFile;

/**
* @Auther: Lance(ZYH)
* @Date: 2018/8/27 14:16
* @Description: Excel处理业务
*/
public interface ExcelService {

/**
* excel文件上传
* @param fileName
* @param file
*/
void uploadExcel(String fileName, MultipartFile file) throws Exception;

}
Loading

0 comments on commit 2a03e12

Please sign in to comment.