private void close(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException e) {
LOGGER.error(“Close io stream error”, e);
}
}
}
}
(@RequestParam(value = “serviceFile”) MultipartFile serviceFile)
这里上传 Excel
文件用的是 MultipartFile
3、实体类 UploadEasyExcelData
package com.riemann.springbootdemo.model;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
-
@author riemann
-
@date 2019/12/19 23:08
*/
@NoArgsConstructor
@Data
@Getter
@Setter
public class UploadEasyExcelData {
@ExcelProperty(value = “name”, index = 0)
private String name;
@ExcelProperty(value = “sex”, index = 1)
private String sex;
@ExcelProperty(value = “age”, index = 2)
private Integer age;
@ExcelProperty(value = “address”, index = 3)
private String address;
@ExcelProperty(value = “phone”, index = 4)
private String phone;
}
这里的实体类是是与上传的 Excel
的信息相对应,这里也用了 lombok
,lombok
能通过注解的方式,在编译时自动为属性生成构造器、getter/setter、equals、hashcode、toString
方法。出现的神奇就是在源码中没有getter
和setter
方法,但是在编译生成的字节码文件中有getter
和setter
方法。这样就省去了手动重建这些代码的麻烦,使代码看起来更简洁