JWRequestMappingHandlerMapping.java 1.1 KB

1234567891011121314151617181920212223242526272829
  1. package com.yihu.jw.version;
  2. import org.springframework.core.annotation.AnnotationUtils;
  3. import org.springframework.web.servlet.mvc.condition.RequestCondition;
  4. import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
  5. import java.lang.reflect.Method;
  6. /**
  7. * Created by chenweida on 2017/6/15.
  8. * 扩展spring的RequestMappingHandlerMapping
  9. */
  10. public class JWRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
  11. @Override
  12. protected RequestCondition<ApiVesrsionCondition> getCustomTypeCondition(Class<?> handlerType) {
  13. ApiVersion apiVersion = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class);
  14. return createCondition(apiVersion);
  15. }
  16. @Override
  17. protected RequestCondition<ApiVesrsionCondition> getCustomMethodCondition(Method method) {
  18. ApiVersion apiVersion = AnnotationUtils.findAnnotation(method, ApiVersion.class);
  19. return createCondition(apiVersion);
  20. }
  21. private RequestCondition<ApiVesrsionCondition> createCondition(ApiVersion apiVersion) {
  22. return apiVersion == null ? null : new ApiVesrsionCondition(apiVersion.value());
  23. }
  24. }