springboot+easypoi导入导出excel数据
1.导出数据
导入依赖
<!--easypoi依赖(表格导入导出)-->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>
对需要操作的表格的实体类加上注解,全部属性都加上@Excel注解
//Employee实体类中
@Excel(name = "员工姓名")
private String name;
@Excel(name = "性别")
private String gender;
//如果有时间类属性,可以用format格式化一下,width设置长度
@Excel(name = "出生日期",width = 20,format = "yyyy-MM-dd")
private LocalDate birthday;
//如果有对象属性,则需要换成@ExcelEntity注解
@ExcelEntity(name = "部门")
private Department department;
在标注了@ExcelEntity属性的实体类中,在需要获取该对象的某个属性上 加上@Excel注解
//Department实体类中
@Excel(name = "部门")
private String name;
控制类
@GetMapping(value = "/export",produces = "application/octet-stream")
public void exportEmployee(HttpServletResponse response){
//获取所有员工数据
List<Employee> list = employeeService<