Search in sources :

Example 1 with ActionMapping

use of cn.taketoday.web.annotation.ActionMapping in project today-framework by TAKETODAY.

the class HandlerMethodRegistry method buildHandlerMethod.

/**
 * Set Action Mapping
 *
 * @param beanName bean name
 * @param method Action or Handler
 * @param beanClass Controller
 * @param controllerMapping find mapping on class
 */
protected void buildHandlerMethod(String beanName, Method method, Class<?> beanClass, @Nullable MergedAnnotation<ActionMapping> controllerMapping) {
    MergedAnnotation<ActionMapping> annotation = MergedAnnotations.from(method).get(ActionMapping.class);
    if (annotation.isPresent()) {
        // build HandlerMethod
        ActionMappingAnnotationHandler handler = createHandler(beanName, beanClass, method);
        // do mapping url
        mappingHandlerMethod(handler, controllerMapping, annotation);
    }
}
Also used : ActionMapping(cn.taketoday.web.annotation.ActionMapping) ActionMappingAnnotationHandler(cn.taketoday.web.handler.method.ActionMappingAnnotationHandler)

Example 2 with ActionMapping

use of cn.taketoday.web.annotation.ActionMapping in project today-framework by TAKETODAY.

the class RequestPathMappingHandlerMethodRegistryTests method mappingHandlerMethod.

@Test
public void mappingHandlerMethod() throws Exception {
    AnnotationAttributes mapping = new AnnotationAttributes();
    Method method = TEST.class.getDeclaredMethod("mapping");
    MergedAnnotation<ActionMapping> actionMapping = MergedAnnotations.from(method).get(ActionMapping.class);
    MergedAnnotation<ActionMapping> controllerMapping = MergedAnnotations.from(method).get(ActionMapping.class);
    RequestPathMappingHandlerMapping registry = new RequestPathMappingHandlerMapping();
    registry.mergeMappingAttributes(mapping, actionMapping, controllerMapping);
    System.out.println(mapping);
}
Also used : AnnotationAttributes(cn.taketoday.core.annotation.AnnotationAttributes) ActionMapping(cn.taketoday.web.annotation.ActionMapping) HttpMethod(cn.taketoday.http.HttpMethod) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 3 with ActionMapping

use of cn.taketoday.web.annotation.ActionMapping in project today-infrastructure by TAKETODAY.

the class RequestMappingHandlerMapping method createRequestMappingInfo.

/**
 * Delegates to {@link #createRequestMappingInfo(ActionMapping, RequestCondition)},
 * supplying the appropriate custom {@link RequestCondition} depending on whether
 * the supplied {@code annotatedElement} is a class or method.
 *
 * @see #getCustomTypeCondition(Class)
 * @see #getCustomMethodCondition(Method)
 */
@Nullable
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
    ActionMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, ActionMapping.class);
    RequestCondition<?> condition = element instanceof Class ? getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element);
    return requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null;
}
Also used : ActionMapping(cn.taketoday.web.annotation.ActionMapping) HttpMethod(cn.taketoday.http.HttpMethod) Method(java.lang.reflect.Method) Nullable(cn.taketoday.lang.Nullable)

Example 4 with ActionMapping

use of cn.taketoday.web.annotation.ActionMapping in project today-infrastructure by TAKETODAY.

the class RequestPathMappingHandlerMethodRegistryTests method mappingHandlerMethod.

@Test
public void mappingHandlerMethod() throws Exception {
    AnnotationAttributes mapping = new AnnotationAttributes();
    Method method = TEST.class.getDeclaredMethod("mapping");
    MergedAnnotation<ActionMapping> actionMapping = MergedAnnotations.from(method).get(ActionMapping.class);
    MergedAnnotation<ActionMapping> controllerMapping = MergedAnnotations.from(method).get(ActionMapping.class);
    RequestPathMappingHandlerRegistry registry = new RequestPathMappingHandlerRegistry();
    registry.mergeMappingAttributes(mapping, actionMapping, controllerMapping);
    System.out.println(mapping);
}
Also used : AnnotationAttributes(cn.taketoday.core.annotation.AnnotationAttributes) ActionMapping(cn.taketoday.web.annotation.ActionMapping) HttpMethod(cn.taketoday.http.HttpMethod) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Aggregations

ActionMapping (cn.taketoday.web.annotation.ActionMapping)4 HttpMethod (cn.taketoday.http.HttpMethod)3 Method (java.lang.reflect.Method)3 AnnotationAttributes (cn.taketoday.core.annotation.AnnotationAttributes)2 Test (org.junit.jupiter.api.Test)2 Nullable (cn.taketoday.lang.Nullable)1 ActionMappingAnnotationHandler (cn.taketoday.web.handler.method.ActionMappingAnnotationHandler)1