1 Star 0 Fork 387

developer_dhq / source-code-hunter

forked from doocs / source-code-hunter 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Spring-OrderUtils.md 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
ylb 提交于 2020-09-03 17:04 . fix: 更新文档格式

Spring OrderUtils

  • Author: HuiFer
  • 源码阅读仓库: SourceHot-Spring
  • org.springframework.core.annotation.OrderUtils主要方法如下
    1. getOrder
    2. getPriority
  • 测试类org.springframework.core.annotation.OrderUtilsTests
    @Nullable
    public static Integer getOrder(Class<?> type) {
        // 缓存中获取
        Object cached = orderCache.get(type);
        if (cached != null) {
            // 返回 int
            return (cached instanceof Integer ? (Integer) cached : null);
        }
        /**
         * 注解工具类,寻找{@link Order}注解
         */
        Order order = AnnotationUtils.findAnnotation(type, Order.class);
        Integer result;
        if (order != null) {
            // 返回
            result = order.value();
        } else {
            result = getPriority(type);
        }
        // key: 类名,value: intValue
        orderCache.put(type, (result != null ? result : NOT_ANNOTATED));
        return result;
    }
    @Nullable
    public static Integer getPriority(Class<?> type) {
        if (priorityAnnotationType == null) {
            return null;
        }
        // 缓存中获取
        Object cached = priorityCache.get(type);
        if (cached != null) {
            // 不为空返回
            return (cached instanceof Integer ? (Integer) cached : null);
        }
        // 注解工具获取注解
        Annotation priority = AnnotationUtils.findAnnotation(type, priorityAnnotationType);
        Integer result = null;
        if (priority != null) {
            // 获取 value
            result = (Integer) AnnotationUtils.getValue(priority);
        }
        // 向缓存插入数据
        priorityCache.put(type, (result != null ? result : NOT_ANNOTATED));
        return result;
    }
1
https://gitee.com/dhq/source-code-hunter.git
git@gitee.com:dhq/source-code-hunter.git
dhq
source-code-hunter
source-code-hunter
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891