Java代码段
/**
* 人员信息导出
*/
@ApiOperation(value = "导出人员信息列表", notes = "导出人员信息列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "USERID", value = "用户名"),
@ApiImplicitParam(name = "USERNAME", value = "姓名"),
@ApiImplicitParam(name = "EMP_CODE", value = "职工号")
})
@GetMapping("export")
public ResultData> export(@ApiIgnore ModelMap map, HttpServletRequest request, HttpServletResponse response, PersonParams personParams) {
ResultData> result = new ResultData>();
try {
List list = personService.getPersonList(personParams);
ExportParams params = new ExportParams(null, "人员信息", ExcelType.XSSF);
if (!ToolsUtil.isEmpty(list)) {
map.put(TemplateExcelConstants.FILE_NAME, "人员信息");
map.put(NormalExcelConstants.DATA_LIST, list);
map.put(NormalExcelConstants.CLASS, PersonExcel.class);
map.put(NormalExcelConstants.PARAMS, params);
PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
return result.returnMessage(HttpStatus.SUCCESS, "导出成功");
} else {
return result.returnMessage(HttpStatus.SUCCESS, "无数据");
}
} catch (Exception e) {
e.printStackTrace();
}
return result.returnMessage(HttpStatus.ERROR, "导出失败");
}
PersonExcel
import java.util.Date;
@Data
public class PersonExcel {
/**
* ID
*/
@ExcelIgnore
private Long id;
/**
* 用户名
*/
@Excel(name = "用户名", width = 20)
private String userId;
/**
* 姓名
*/
@Excel(name = "姓名", width = 20)
private String userName;
/**
* 职工号
*/
@Excel(name = "职工号", width = 20)
private String empCode;
/**
* 性别
*/
@Excel(name = "性别", width = 10)
private String sex;
/**
* 密码
*/
@ExcelIgnore
private String password;
/**
* 身份z号
*/
@Excel(name = "身份z号", width = 30)
private String personCode;
/**
* 相片
*/
@ExcelIgnore
private String photo;
/**
* 手机号
*/
@Excel(name = "手机", width = 30)
private Long mobilePhone;
/**
* 固定电话
*/
@Excel(name = "座机", width = 30)
private Long phone;
}
pom.xml (全用比较保险吧,懒得去测试排除哪些不需要了)
cn.afterturn
easypoi-web
4.4.0
cn.afterturn
easypoi-base
4.4.0
cn.afterturn
easypoi-annotation
4.4.0
cn.hutool
hutool-all
5.7.13
commons-io
commons-io
2.3
org.apache.poi
poi
4.1.2
org.apache.poi
poi-ooxml
4.1.2
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)