ParameterHelper.java 2.21 KB
Newer Older
duanledexianxianxian's avatar
duanledexianxianxian committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
package com.apigcc.springmvc;

import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.Parameter;

public class ParameterHelper {

    public static final String ANNOTATION_REQUEST_PARAM = "RequestParam";
    public static final String ANNOTATION_REQUEST_HEADER = "RequestHeader";
    public static final String ANNOTATION_REQUEST_ATTRIBUTE = "RequestAttribute";
    public static final String ANNOTATION_REQUEST_PART = "RequestPart";
    public static final String ANNOTATION_COOKIE_VALUE = "CookieValue";
    public static final String ANNOTATION_PATH_VARIABLE = "PathVariable";
    public static final String ANNOTATION_REQUEST_BODY = "RequestBody";
    public static final String ANNOTATION_MULTIPART_FILE = "MultipartFile";

    public static boolean hasRequestBody(NodeList<Parameter> parameters) {
        for (Parameter parameter : parameters) {
            if (isRequestBody(parameter)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isRequestParam(Parameter parameter) {
        if (!parameter.isAnnotationPresent(ANNOTATION_PATH_VARIABLE) &&
                !parameter.isAnnotationPresent(ANNOTATION_REQUEST_BODY) &&
                !parameter.isAnnotationPresent(ANNOTATION_REQUEST_HEADER) &&
                !parameter.isAnnotationPresent(ANNOTATION_COOKIE_VALUE) &&
                !parameter.isAnnotationPresent(ANNOTATION_REQUEST_PART) &&
                !parameter.isAnnotationPresent(ANNOTATION_MULTIPART_FILE) &&
                !parameter.isAnnotationPresent(ANNOTATION_REQUEST_ATTRIBUTE)) {
            return true;
        }
        return false;
    }

    public static boolean isPathVariable(Parameter parameter) {
        if (parameter.isAnnotationPresent(ANNOTATION_PATH_VARIABLE)) {
            return true;
        }
        return false;
    }

    public static boolean isRequestBody(Parameter parameter) {
        if (parameter.isAnnotationPresent(ANNOTATION_REQUEST_BODY)) {
            return true;
        }
        return false;
    }

    public static boolean isRequestHeader(Parameter parameter) {
        if (parameter.isAnnotationPresent(ANNOTATION_REQUEST_HEADER)) {
            return true;
        }
        return false;
    }

}