Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
tangllty committed May 24, 2024
1 parent f41aef1 commit d312fee
Showing 1 changed file with 1 addition and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,11 @@ object ExcelUtils {

return fields
.filter { it.isAnnotationPresent(Excel::class.java) }
.map { field -> field to getAnnotation(field, Excel::class.java) }
.map { field -> field to AnnotationUtils.getAnnotation(field, Excel::class.java)!! }
.sortedBy { it.second.sort }
.associateByTo(LinkedHashMap(), { it.first }, { it.second })
}

/**
* 此方法不会抛出异常,目的是消除AnnotationUtils.getAnnotation返回值可能为空的警告
* .filter { it.isAnnotationPresent(Excel::class.java) } 已经过滤无Excel注解的字段
*/
private fun getAnnotation(annotatedElement: Field, annotationType: Class<Excel>): Excel {
return AnnotationUtils.getAnnotation(annotatedElement, annotationType) ?: throw IllegalStateException("Annotation not found")
}

/**
* 响应 Excel
*
Expand Down

0 comments on commit d312fee

Please sign in to comment.