考试导出

beetlsql3-dev
Mlxa0324 2 years ago
parent 8f8be198f5
commit fa034cd7d2

@ -109,15 +109,16 @@ public class BeanUtil extends cn.hutool.core.bean.BeanUtil {
*/
public static <T extends BaseEntity> Map<String, String> processExcelAnnotationToMap(@NotNull Class<T> clazz) {
Map<String, String> result = new ConcurrentHashMap<>(16);
final Class<ExcelProperty> cls = ExcelProperty.class;
Arrays.stream(clazz.getDeclaredFields())
// 过滤有指定注解的属性
.filter(declaredField -> ObjectUtil.isNotNull(AnnotationUtils.findAnnotation(declaredField, ExcelProperty.class)))
.filter(declaredField -> ObjectUtil.isNotNull(AnnotationUtils.findAnnotation(declaredField, cls)))
// 根据index属性排序,并放置到Map的返回值中
.sorted(Comparator.comparingInt(o -> AnnotationUtils.findAnnotation(o, ExcelProperty.class).index()))
.sorted(Comparator.comparingInt(o -> AnnotationUtils.findAnnotation(o, cls).index()))
// 有序执行
.forEachOrdered(field -> {
ExcelProperty annotation = AnnotationUtils.findAnnotation(field, ExcelProperty.class);
ExcelProperty annotation = AnnotationUtils.findAnnotation(field, cls);
String title = annotation.value()[0];
result.put(field.getName(), title);
});

Loading…
Cancel
Save