记录excel转换类型报错问题
1.pom
```sql
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.17</version>
</dependency>
2.实体类 (实体不是字符串类型必须开头否则会转换类型报错问题)
package com.ty.model.po;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class ApproveExcelW implements Serializable{
private Integer deptId;
private Integer carType;
@ExcelProperty("部门名称")
private String deptName;
@ExcelProperty("车牌号码")
private String plateNumber;
@ExcelProperty(value = "停车场")
private String parking;
@ExcelProperty("性别")
private String gender;
@ExcelProperty("车辆类型")
private String carTypes;
@ExcelProperty("驾驶员姓名")
private String driverName;
@ExcelProperty("驾驶员手机号")
private String driverPhone;
@ExcelProperty("证件号码")
private String idCardNo;
@ExcelProperty("起始时间")
private String startDate;
@ExcelProperty("到期时间")
private String endDate;
@ExcelProperty("备注")
private String detail;
@ExcelProperty("图片")
private String url;
}
3.控制层
@ApiOperation(value = “通过本地文件导入数据 根据车牌 起始时间区分”)
@PostMapping(value = “/importDataExcelData”)
public Result importDataExcelData(@RequestPart(“file”) MultipartFile file) {
List memberList = null;
try {
memberList = EasyExcel.read(file.getInputStream()).head(ApproveExcelW.class).sheet().doReadSync();
if (memberList == null) {
return Result.err(“文档暂无数据”, ApproveExcelW.class);
}
approveService.importDataExcelData(memberList);
return Result.ok(true);
} catch (IOException e) {
e.printStackTrace();
}
return Result.ok(false);
}