在上一篇文章中,我们实现了了自定义注解导出excel及对date类型和枚举类型进行处理。虽然效果是出来了,但是还是有问题的。
问题分析:
1:在处理date类型及枚举类型的时候,很麻烦,需要好几个属性配合这使用。如果忘了其中的一个就会导致错。如下图:

941b76aaa208cbd5ae21b1657c4f75cd.png
还记的在《Java中注解学习系列教程-3》中我们知道,自定义注解的成员属性还可以是一种特殊的类型:Annotation的。也就是在注解中使用注解。
所以我们根据这个特性来处理:
将日期类型转换及枚举类转换封装到两个不同的注解中。
一:封装枚举类的注解
1.1:在我们自定义excel解析的注解ExcelAnnotation类中定义解析枚举类的注解。如下图:
/**
* 声明枚举类解析对象
* @return
*/
public abstract EnumCode2Description[] EnumCode2Description() default {};
/**
* 枚举类 code转 description
*/
@Retention(RetentionPolicy.RUNTIME)
@Target( {})
public @interface EnumCode2Description{
/**
* 调用枚举列的方法名称
* @return
*/
public abstract String methodName();
/**
* 调用枚举类方法的参数
* @return
*/
public abstract Class methodArgClass() default Integer.class;
/**
* 枚举类
* @return
*/
public abstract Class clazz();
}

735215f97e5caef51b89c4c6aeb08e7b.png

576266234f9ed3ceb6f0f0f2cbc03b01.png
1.2:在实体对象中使用该注解

0b2ec5873b9e074fd15c9f9f3b051954.png
1.3:解析注解中处理

40e46444fb159046443976697ff16542.png
二:日期格式化封装
2.1:在自定义注解中定义日期格式注解
/**
* 声明解析日期封装对象
* @return
*/
public abstract myDateFormat2Pattern[] myDateFormat2Pattern() default {};
/**
* 日期格式化-封装注解
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({})
public @interface myDateFormat2Pattern{
public abstract String pattern() ;
public abstract boolean isDateFormate() ;
}

e7e99ebb7ca1c61b03d223d07043fd67.png
2.2:定义格式对象为成员属性

d74aa2ea679b71f670423065f96f5d22.png
2.3:使用封装后的日期注解

c0a0e17dfc915bd08cd33093383e170d.png
2.4:解析封装的日期注解

2c19d678852723ec33cdbc7b519d07d2.png
代码以放git上了。