jetbrick-webmvc/src/main/java/jetbrick/web/mvc/router/RestfulRouter.java
@Override
    public void registerController(Class<?> clazz) {
        Controller controller = clazz.getAnnotation(Controller.class);
        Validate.notNull(controller);

        String ctrlPath = ValueConstants.trimToEmpty(controller.value());
        ControllerInfo ctrlInfo = new ControllerInfo(clazz, controller);

        ResultHandlerResolver resultHandlerResolver = WebConfig.getInstance().getResultHandlerResolver();
        KlassInfo klass = KlassInfo.create(clazz);
        for (MethodInfo actionMethod : klass.getMethods()) {
            if (!klass.isPublic() || actionMethod.isStatic()) {
                continue;
            }
            Action action = actionMethod.getAnnotation(Action.class);
            if (action == null) {
                continue;
            }
            String actionPath = ValueConstants.defaultValue(action.value(), actionMethod.getName());
            String url = StringUtils.removeEnd(ctrlPath, "/") + StringUtils.prefix(actionPath, "/");

            // validate the action result type
            Class<?> returnClass = actionMethod.getRawReturnType(clazz);
            if (!resultHandlerResolver.validate(returnClass)) {
                throw new IllegalStateException("Unsupported result class: " + returnClass.getName() + " of " + actionMethod);
            }

            HttpMethod[] httpMethods = action.method();
            Validate.isTrue(httpMethods.length > 0);

            if (log.isDebugEnabled()) {
                log.debug("found action: {} {}", ArrayUtils.toString(httpMethods), url);
            }
            ActionInfo actionInfo = new ActionInfo(ctrlInfo, actionMethod, url);
            for (HttpMethod method : httpMethods) {
                RestfulMatcher matcher = matchers[method.getIndex()];
                if (matcher == null) {
                    matcher = new RestfulMatcher();
                    matchers[method.getIndex()] = matcher;
                }
                matcher.register(actionInfo, url);
            }
        }
    }
@Override
    public void registerController(Class<?> clazz) {
        Controller controller = clazz.getAnnotation(Controller.class);
        Validate.notNull(controller);

        String ctrlPath = ValueConstants.trimToEmpty(controller.value());
        ControllerInfo ctrlInfo = new ControllerInfo(clazz, controller);

        ResultHandlerResolver resultHandlerResolver = WebConfig.getInstance().getResultHandlerResolver();
        KlassInfo klass = KlassInfo.create(clazz);
        for (MethodInfo actionMethod : klass.getMethods()) {
            if (!klass.isPublic() || actionMethod.isStatic()) {
                continue;
            }
            Action action = actionMethod.getAnnotation(Action.class);
            if (action == null) {
                continue;
            }
            String actionPath = ValueConstants.defaultValue(action.value(), actionMethod.getName());
            String url = StringUtils.removeEnd(ctrlPath, "/") + StringUtils.prefix(actionPath, "/");

            // validate the action result type
            Class<?> returnClass = actionMethod.getRawReturnType(clazz);
            if (!resultHandlerResolver.validate(returnClass)) {
                throw new IllegalStateException("Unsupported result class: " + returnClass.getName() + " of " + actionMethod);
            }

            HttpMethod[] httpMethods = action.method();
            Validate.isTrue(httpMethods.length > 0);

            if (log.isDebugEnabled()) {
                log.debug("found action: {} {}", ArrayUtils.toString(httpMethods), url);
            }
            ActionInfo actionInfo = new ActionInfo(ctrlInfo, actionMethod, url);
            for (HttpMethod method : httpMethods) {
                RestfulMatcher matcher = matchers[method.getIndex()];
                if (matcher == null) {
                    matcher = new RestfulMatcher();
                    matchers[method.getIndex()] = matcher;
                }
                matcher.register(actionInfo, url);
            }
        }
    }
@ Override public void registerController ( Class < ? > clazz ) { Controller controller = clazz . getAnnotation ( Controller . class ) ; Validate . notNull ( controller ) ; String ctrlPath = ValueConstants . trimToEmpty ( controller . value ( ) ) ; ControllerInfo ctrlInfo = new ControllerInfo ( clazz , controller ) ; ResultHandlerResolver resultHandlerResolver = WebConfig . getInstance ( ) . getResultHandlerResolver ( ) ; KlassInfo klass = KlassInfo . create ( clazz ) ; for ( MethodInfo actionMethod : klass . getMethods ( ) ) { if ( ! klass . isPublic ( ) || actionMethod . isStatic ( ) ) { continue ; } Action action = actionMethod . getAnnotation ( Action . class ) ; if ( action == null ) { continue ; } String actionPath = ValueConstants . defaultValue ( action . value ( ) , actionMethod . getName ( ) ) ; String url = StringUtils . removeEnd ( ctrlPath , "/" ) + StringUtils . prefix ( actionPath , "/" ) ; // validate the action result type Class < ? > returnClass = actionMethod . getRawReturnType ( clazz ) ; if ( ! resultHandlerResolver . validate ( returnClass ) ) { throw new IllegalStateException ( "Unsupported result class: " + returnClass . getName ( ) + " of " + actionMethod ) ; } HttpMethod [ ] httpMethods = action . method ( ) ; Validate . isTrue ( httpMethods . length > 0 ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "found action: {} {}" , ArrayUtils . toString ( httpMethods ) , url ) ; } ActionInfo actionInfo = new ActionInfo ( ctrlInfo , actionMethod , url ) ; for ( HttpMethod method : httpMethods ) { RestfulMatcher matcher = matchers [ method . getIndex ( ) ] ; if ( matcher == null ) { matcher = new RestfulMatcher ( ) ; matchers [ method . getIndex ( ) ] = matcher ; } matcher . register ( actionInfo , url ) ; } } }
根据 annotation，获取所有的 Action
根据 annotation，获取所有的 Action