提交 9b0e2182 authored 作者: 孙于凯's avatar 孙于凯

feat:新增easypoi 导入

上级
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="syk-demo" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="syk-demo" options="-parameters" />
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://maven.aliyun.com/repository/public" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>syk-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>syk-demo</name>
<description>syk-demo</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</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>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!--activemq-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--easy poi依赖-->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.example.sykdemo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@EnableSwagger2
@MapperScan("com.example.sykdemo.mapper")
@EnableScheduling
public class SykDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SykDemoApplication.class, args);
}
}
package com.example.sykdemo.config;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.jms.Queue;
import javax.jms.Topic;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
@Configuration
public class ActiveMQConfig {
@Bean
public Queue logQueue(){
return new ActiveMQQueue("fore.queue");
}
@Bean
public Topic createTopic(){
return new ActiveMQTopic("java2.bos.sms");
}
public static void main(String[] args) {
ArrayList<String> list=new ArrayList<>();
list.add("张无忌-男-14");
list.add("手机号-女-11");
list.add("阿斯顿-男-10");
list.add("张强-女-15");
list.add("张三丰-男-55");
list.add("张三丰-女-22");
list.add("张翠山-男-23");
list.add("张良-女-16");
list.add("王二麻子-男-33");
list.add("谢广坤-女-30");
//
// list.stream().map(s -> Integer.parseInt(s.split("-")[1])).forEach(a->System.out.println(a));
List<String> a = list.stream()
.filter(s -> "男".equals(s.split("-")[1]))
.collect(Collectors.toList());
// a.forEach(System.out::println);
List<Integer> sz= Arrays.asList(1,2,3,4,5,6,7,8,9,10);
sz.stream()
.filter(number->number%2!=0);
// .forEach(o->System.out.println(o));
list.stream()
.filter(s->"男".equals(s.split("-")[1]));
}
}
package com.example.sykdemo.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
/**
* @author syk
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket docket(Environment environment)
{
Profiles profiles= Profiles.of("dev","test");
boolean flag = environment.acceptsProfiles(profiles);
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.enable(flag)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.sykdemo.controller"))
.build();
}
private ApiInfo apiInfo()
{
Contact contact = new Contact("syk", "https://www.cnblogs.com/sykswagger", "1172648124@qq.com");
return new ApiInfo(
"这里对应 Api Documentation",
"这里对应 Api Documentation",
"这里对应 v1.0",
"https://www.cnblogs.com/sykswagger",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList());
}
}
package com.example.sykdemo.config;
public class TestPOI {
}
package com.example.sykdemo.controller;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.example.sykdemo.entity.User;
import com.example.sykdemo.mapper.UserMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
@Api(tags = "测试easypoi导入")
@RestController
@RequestMapping("/aa")
public class EasyPoiController {
@Resource
private UserMapper userMapper;
@PostMapping ("/testImport")
@ApiOperation("导入数据库")
public void testImport(MultipartFile file) throws Exception {
if (file == null || file.isEmpty()) {
throw new IllegalArgumentException("上传的文件不能为空");
}
ImportParams importParams = new ImportParams();
//标题列占得行数
importParams.setTitleRows(0);
//header列占的行数
importParams.setHeadRows(1);
List<User> users = ExcelImportUtil.importExcel(file.getInputStream(), User.class, importParams);
for (User user : users) {
userMapper.insert(user);
}
}
}
package com.example.sykdemo.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import javax.print.attribute.standard.MediaSize;
import java.io.Serializable;
import java.util.Date;
@Data
public class User implements Serializable {
@Excel(name = "基地")
private String base;
@Excel(name="姓名")
private String name;
@Excel(name="性别")
private String sex;
@Excel(name="生日",format = "yyyy-MM-dd")
private Date bir;
}
package com.example.sykdemo.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.sykdemo.entity.User;
import org.mapstruct.Mapper;
@Mapper
public interface UserMapper extends BaseMapper<User> {
}
package com.example.sykdemo.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.sykdemo.entity.User;
public interface UserService extends IService<User> {
}
package com.example.sykdemo.service.impl;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sykdemo.entity.User;
import com.example.sykdemo.mapper.UserMapper;
import com.example.sykdemo.service.UserService;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
}
spring.profiles.active=dev
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Asia/Shanghai&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
## MQ??????
#spring.activemq.broker-url=tcp://127.0.0.1:61616
## ??????MQ
#spring.activemq.in-memory=false
## ???
#spring.activemq.password=admin
## ??
#spring.activemq.user=admin
\ No newline at end of file
package com.example.sykdemo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SykDemoApplicationTests {
@Test
void contextLoads() {
}
}
spring.profiles.active=dev
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Asia/Shanghai&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
## MQ??????
#spring.activemq.broker-url=tcp://127.0.0.1:61616
## ??????MQ
#spring.activemq.in-memory=false
## ???
#spring.activemq.password=admin
## ??
#spring.activemq.user=admin
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论