1234567891011121314151617181920212223242526272829 |
- package com.yihu.jw.version;
- import org.springframework.core.annotation.AnnotationUtils;
- import org.springframework.web.servlet.mvc.condition.RequestCondition;
- import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
- import java.lang.reflect.Method;
- /**
- * Created by chenweida on 2017/6/15.
- * 扩展spring的RequestMappingHandlerMapping
- */
- public class JWRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
- @Override
- protected RequestCondition<ApiVesrsionCondition> getCustomTypeCondition(Class<?> handlerType) {
- ApiVersion apiVersion = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class);
- return createCondition(apiVersion);
- }
- @Override
- protected RequestCondition<ApiVesrsionCondition> getCustomMethodCondition(Method method) {
- ApiVersion apiVersion = AnnotationUtils.findAnnotation(method, ApiVersion.class);
- return createCondition(apiVersion);
- }
- private RequestCondition<ApiVesrsionCondition> createCondition(ApiVersion apiVersion) {
- return apiVersion == null ? null : new ApiVesrsionCondition(apiVersion.value());
- }
- }
|