Package org.springframework.web.bind.annotation

Examples of org.springframework.web.bind.annotation.RequestMapping


   * Validate the given annotated handler against the current request.
   * @see #validateMapping
   */
  @Override
  protected void validateHandler(Object handler, HttpServletRequest request) throws Exception {
    RequestMapping mapping = this.cachedMappings.get(handler.getClass());
    if (mapping == null) {
      mapping = AnnotationUtils.findAnnotation(handler.getClass(), RequestMapping.class);
    }
    if (mapping != null) {
      validateMapping(mapping, request);
View Full Code Here


    @Override
    protected boolean isHandlerMethod(Method method) {
      if (this.mappings.containsKey(method)) {
        return true;
      }
      RequestMapping mapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
      if (mapping != null) {
        String[] patterns = mapping.value();
        RequestMethod[] methods = new RequestMethod[0];
        String[] params = new String[0];
        String[] headers = new String[0];
        if (!hasTypeLevelMapping() || !Arrays.equals(mapping.method(), getTypeLevelMapping().method())) {
          methods = mapping.method();
        }
        if (!hasTypeLevelMapping() || !Arrays.equals(mapping.params(), getTypeLevelMapping().params())) {
          params = mapping.params();
        }
        if (!hasTypeLevelMapping() || !Arrays.equals(mapping.headers(), getTypeLevelMapping().headers())) {
          headers = mapping.headers();
        }
        RequestMappingInfo mappingInfo = new RequestMappingInfo(patterns, methods, params, headers);
        this.mappings.put(method, mappingInfo);
        return true;
      }
View Full Code Here

   * annotation on the handler class and on any of its methods.
   */
  protected String[] determineUrlsForHandler(String beanName) {
    ApplicationContext context = getApplicationContext();
    Class<?> handlerType = context.getType(beanName);
    RequestMapping mapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);

    if (mapping == null && context instanceof ConfigurableApplicationContext &&
        context.containsBeanDefinition(beanName)) {
      ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
      BeanDefinition bd = cac.getBeanFactory().getMergedBeanDefinition(beanName);
      if (bd instanceof AbstractBeanDefinition) {
        AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
        if (abd.hasBeanClass()) {
          Class<?> beanClass = abd.getBeanClass();
          mapping = AnnotationUtils.findAnnotation(beanClass, RequestMapping.class);
        }
      }
    }

    if (mapping != null) {
      if (mapping.method().length > 0 || mapping.params().length > 0) {
        throw new IllegalStateException("Only path value supported for RequestMapping annotation " +
            "at the type level - map HTTP method and/or parameters at the method level! " +
            "Offending type: " + handlerType);
      }
      final Set<String> urls = new LinkedHashSet<String>();
      String[] paths = mapping.value();
      for (String path : paths) {
        addUrlsForPath(urls, path);
      }
      return StringUtils.toStringArray(urls);
    }
    else if (AnnotationUtils.findAnnotation(handlerType, Controller.class) != null) {
      final Set<String> urls = new LinkedHashSet<String>();
      ReflectionUtils.doWithMethods(handlerType, new ReflectionUtils.MethodCallback() {
        public void doWith(Method method) {
          RequestMapping mapping = method.getAnnotation(RequestMapping.class);
          if (mapping != null) {
            String[] mappedPaths = mapping.value();
            for (int i = 0; i < mappedPaths.length; i++) {
              addUrlsForPath(urls, mappedPaths[i]);
            }
          }
        }
View Full Code Here

      Map<RequestMappingInfo, Method> targetHandlerMethods = new LinkedHashMap<RequestMappingInfo, Method>();
      Map<RequestMappingInfo, String> targetPathMatches = new LinkedHashMap<RequestMappingInfo, String>();
      String resolvedMethodName = null;
      for (Method handlerMethod : this.handlerMethods) {
        RequestMappingInfo mappingInfo = new RequestMappingInfo();
        RequestMapping mapping = AnnotationUtils.findAnnotation(handlerMethod, RequestMapping.class);
        mappingInfo.paths = mapping.value();
        mappingInfo.methods = mapping.method();
        mappingInfo.params = mapping.params();
        boolean match = false;
        if (mappingInfo.paths.length > 0) {
          for (String mappedPath : mappingInfo.paths) {
            if (isPathMatch(mappedPath, lookupPath)) {
              if (checkParameters(request, mappingInfo)) {
View Full Code Here

    @Override
    protected boolean isHandlerMethod(Method method) {
      if (this.mappings.containsKey(method)) {
        return true;
      }
      RequestMapping mapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
      if (mapping != null) {
        String[] patterns = mapping.value();
        RequestMethod[] methods = new RequestMethod[0];
        String[] params = new String[0];
        String[] headers = new String[0];
        if (!hasTypeLevelMapping() || !Arrays.equals(mapping.method(), getTypeLevelMapping().method())) {
          methods = mapping.method();
        }
        if (!hasTypeLevelMapping() || !Arrays.equals(mapping.params(), getTypeLevelMapping().params())) {
          params = mapping.params();
        }
        if (!hasTypeLevelMapping() || !Arrays.equals(mapping.headers(), getTypeLevelMapping().headers())) {
          headers = mapping.headers();
        }
        RequestMappingInfo mappingInfo = new RequestMappingInfo(patterns, methods, params, headers);
        this.mappings.put(method, mappingInfo);
        return true;
      }
View Full Code Here

   */
  @Override
  protected String[] determineUrlsForHandler(String beanName) {
    ApplicationContext context = getApplicationContext();
    Class<?> handlerType = context.getType(beanName);
    RequestMapping mapping = context.findAnnotationOnBean(beanName, RequestMapping.class);
    if (mapping != null) {
      // @RequestMapping found at type level
      this.cachedMappings.put(handlerType, mapping);
      Set<String> urls = new LinkedHashSet<String>();
      String[] typeLevelPatterns = mapping.value();
      if (typeLevelPatterns.length > 0) {
        // @RequestMapping specifies paths at type level
        String[] methodLevelPatterns = determineUrlsForHandlerMethods(handlerType, true);
        for (String typeLevelPattern : typeLevelPatterns) {
          if (!typeLevelPattern.startsWith("/")) {
View Full Code Here

    handlerTypes.add(handlerType);
    handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
    for (Class<?> currentHandlerType : handlerTypes) {
      ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
        public void doWith(Method method) {
          RequestMapping mapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
          if (mapping != null) {
            String[] mappedPatterns = mapping.value();
            if (mappedPatterns.length > 0) {
              for (String mappedPattern : mappedPatterns) {
                if (!hasTypeLevelMapping && !mappedPattern.startsWith("/")) {
                  mappedPattern = "/" + mappedPattern;
                }
View Full Code Here

   * Validate the given annotated handler against the current request.
   * @see #validateMapping
   */
  @Override
  protected void validateHandler(Object handler, HttpServletRequest request) throws Exception {
    RequestMapping mapping = this.cachedMappings.get(handler.getClass());
    if (mapping == null) {
      mapping = AnnotationUtils.findAnnotation(handler.getClass(), RequestMapping.class);
    }
    if (mapping != null) {
      validateMapping(mapping, request);
View Full Code Here

      RequestMappingInfo mappingInfo = new RequestMappingInfo();
      ActionMapping actionMapping = AnnotationUtils.findAnnotation(method, ActionMapping.class);
      RenderMapping renderMapping = AnnotationUtils.findAnnotation(method, RenderMapping.class);
      ResourceMapping resourceMapping = AnnotationUtils.findAnnotation(method, ResourceMapping.class);
      EventMapping eventMapping = AnnotationUtils.findAnnotation(method, EventMapping.class);
      RequestMapping requestMapping = AnnotationUtils.findAnnotation(method, RequestMapping.class);
      if (actionMapping != null) {
        mappingInfo.initPhaseMapping(PortletRequest.ACTION_PHASE, actionMapping.value(), actionMapping.params());
      }
      if (renderMapping != null) {
        mappingInfo.initPhaseMapping(PortletRequest.RENDER_PHASE, renderMapping.value(), renderMapping.params());
      }
      if (resourceMapping != null) {
        mappingInfo.initPhaseMapping(PortletRequest.RESOURCE_PHASE, resourceMapping.value(), new String[0]);
      }
      if (eventMapping != null) {
        mappingInfo.initPhaseMapping(PortletRequest.EVENT_PHASE, eventMapping.value(), new String[0]);
      }
      if (requestMapping != null) {
        mappingInfo.initStandardMapping(requestMapping.value(), requestMapping.method(),
            requestMapping.params(), requestMapping.headers());
        if (mappingInfo.phase == null) {
          mappingInfo.phase = determineDefaultPhase(method);
        }
      }
      if (mappingInfo.phase != null) {
View Full Code Here

      for (Object handler : handlers) {
        Class<?> controllerClazz = handler.getClass();
        Method[] methods = controllerClazz.getMethods();
        for (Method method : methods) {
          // 查找RequestMapping注解
          RequestMapping requestMapping = method
              .getAnnotation(RequestMapping.class);
          if (requestMapping == null)
            continue;

          for (String methodName : requestMapping.value()) {
            // 内部URL,仅用于 Spring MVC内部匹配到控制器方法
            // 要获取外部URL,请调用WebContext.getBundleMethodUrl方法
            String innerMappingUrl = methodName;
            if (!innerMappingUrl.startsWith("/")) {
              innerMappingUrl = "/" + innerMappingUrl;
            }
            innerMappingUrl = "/" + bundleName + innerMappingUrl;

            RequestMethod[] requestMethods = requestMapping
                .method();
            // 如果方法为空,则映射所有的HTTP方法
            if (requestMethods == null
                || requestMethods.length == 0) {
              requestMethods = RequestMethod.values();
View Full Code Here

TOP

Related Classes of org.springframework.web.bind.annotation.RequestMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.