java自定义注解在excel导出时的使用

自定义注解:

@Documented
@Target({ElementType.METHOD,ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelColumn {
    String name() default "zhoushun";
}

注解类:

public class ActivityDataDetailBean implements Serializable {

    private static final long serialVersionUID = 7689111063501975678L;
    @ExcelColumn(name="活动ID")
    private int activityId;

    @ExcelColumn(name = "日期")
    private String date;

    @ExcelColumn(name = "城市")
    private String cityName;

    @ExcelColumn(name = "投放位置")
    private String slot;

    @ExcelColumn(name="pageId")
    private String topicId;

    @ExcelColumn(name = "页面PV")
    private Long pv;

    @ExcelColumn(name = "页面UV")
    private Long uv;

    @ExcelColumn(name = "页面点击数")
    private Long click;

    @ExcelColumn(name="页面到达率")
    private String reachRate;

    @ExcelColumn(name = "页面关闭率")
    private String closeRate;

    @ExcelColumn(name = "分享量")
    private Long shareCount;

导出时获取注解内容:

 private static void getReflectInfo(Class<?> c,List<String> head,List<Method> getMethod) throws IntrospectionException {
        Field[] fields = c.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            if (!fields[i].getName().equalsIgnoreCase("serialVersionUID") && !fields[i].getName().equalsIgnoreCase("$jacocoData")) {
                ExcelColumn excelColumns = fields[i].getAnnotation(ExcelColumn.class);
                if (excelColumns != null) {
                    head.add(excelColumns.name());
                } else {
                    head.add(fields[i].getName());
                }
                getMethod.add(new PropertyDescriptor(fields[i].getName(), c).getReadMethod());
            }
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值