导入:
<dependency>
<groupId>com.gaoice</groupId>
<artifactId>easyexcel-spring-boot-starter</artifactId>
<version>1.0</version>
</dependency>
excel和接收类字段对应关系
@Data
@ColumnWidth(30)
public class AppVcardExcelVO {
@ExcelLine
@ExcelIgnore
@Schema(description = "导入时候回显行号")
private Long lineNum;
@NotBlank(message = "客户名不能为空")
@ExcelProperty("客户名")
@Schema(description = "客户名")
private String name;
@NotBlank(message = "手机号不能为空")
@Pattern(regexp = "^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[3,5,6,7,8])|(18[0-9])|(19[8,9]))\\d{8}$", message = "手机号格式不正确")
@ExcelProperty("手机号")
@Schema(description = "手机号")
private String mobile;
@ExcelProperty("邮箱")
@Email(regexp = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$", message = "邮箱格式不正确")
@Schema(description = "邮箱")
private String email;
}
@PostMapping("/importVcard")
public R importVcard(@RequestExcel List<AppVcardExcelVO> excelVOList {
return service.importVcard(excelVOList);
}
这样就可以导入了。
下面是导出:
/**
* 导出
*/
@GetMapping("/exportList")
@ResponseExcel
public List<AppVcardExcelVO> exportList(){
return service.exportList();
}
注意使用注解就可以,导入接收用@RequestExcel,导出用@ResponseExcel,@ColumnWidth自定义导航栏宽度