导入导出EasyPOI @excel注解属性作用 您所在的位置:网站首页 excel表格对齐方式影响导入吗 导入导出EasyPOI @excel注解属性作用

导入导出EasyPOI @excel注解属性作用

2024-07-08 05:37| 来源: 网络整理| 查看: 265

目录

1、@Excel注解使用:

 2、@ExcelTarget注解使用:

 3、@ExcelEntity注解使用:

 4、 @ExcelCollection注解使用:

 5、示例:

1、@Excel注解使用:

@Excel 作用到filed上面,是对Excel一列的一个描述,这个是必须使用的注解,如果需求简单只使用这一个注解也是可以的,涵盖了常用的Excel需求。

 2、@ExcelTarget注解使用:

这个是作用在导出的实体类上面,属性也只有一个id。

 3、@ExcelEntity注解使用:

@ExcelEntity标记是不是导出excel 标记为实体类,一遍是一个内部属性类,标记是否继续穿透,可以自定义内部id。

4、 @ExcelCollection注解使用:

@ExcelCollection一对多的集合注解,用以标记集合是否被数据以及集合的整体排序。

 5、示例:

1、实体类:

@Data @ApiModel("船员信息对象") @JsonIgnoreProperties(value = {"handler"})//是json序列化时忽略bean中的一些属性序列化和反序列化时抛出的异常. public class DmCrewInfo { /** * id */ @Id @ApiModelProperty(value = "id") private String id; /** * 船舶 */ @ApiModelProperty(value = "船舶") @Excel(name = "船舶", orderNum = "1") private String shipName; /** * 姓名 */ @ApiModelProperty(value = "姓名") @Excel(name = "姓名", orderNum = "2") private String name; /** * 出生年月 */ @ApiModelProperty(value = "出生年月") @Excel(name = "出生年月", format = "yyyy-MM", orderNum = "3") private Date birthday; /** * 手机号码 */ @ApiModelProperty(value = "手机号码") @Excel(name = "手机号码", orderNum = "4", width = 20) private String phone; /** * 年龄 */ @ApiModelProperty(value = "年龄") @Excel(name = "年龄", orderNum = "5") private Long age; }

2、调用导出方法:

//allList为需要导出的实体类集合 List allList = dmCrewInfoMapper.selectDmCrewInfoList(exportDmCrewInfo); if (allList != null && allList.size() > 0) { // 导出数据 ExcelUtil.exportExcel(allList, "船员信息数据", "船员信息数据", DmCrewInfo.class, "船员信息数据导出.xls", response); }

3、效果:

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有