cn.schoolwow.quickapi.handler.controller.SpringMVCControllerHandler Maven / Gradle / Ivy
package cn.schoolwow.quickapi.handler.controller;
import cn.schoolwow.quickapi.domain.API;
import cn.schoolwow.quickapi.domain.APIField;
import cn.schoolwow.quickapi.domain.APIParameter;
import cn.schoolwow.quickapi.util.PackageUtil;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public class SpringMVCControllerHandler extends AbstractControllerHandler{
private static LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer();
private static Class[] mappingClasses = new Class[]{
GetMapping.class,PostMapping.class,PutMapping.class,DeleteMapping.class,PatchMapping.class
};
@Override
public String getBaseUrl(Class _class) {
String baseUrl = "";
RequestMapping classRequestMapping = (RequestMapping) _class.getDeclaredAnnotation(RequestMapping.class);
if(classRequestMapping!=null){
baseUrl = classRequestMapping.value()[0];
}
return baseUrl;
}
@Override
public void handleRequestMapping(Method method, API api) {
for(Class _class:mappingClasses){
Annotation annotation = method.getDeclaredAnnotation(_class);
if(annotation==null){
continue;
}
String requestMethod = _class.getSimpleName().substring(0,_class.getSimpleName().lastIndexOf("Mapping")).toUpperCase();
api.methods = new String[]{requestMethod};
try {
String[] values = (String[]) _class.getDeclaredMethod("value").invoke(annotation);
api.url = values[0];
}catch (Exception e){
continue;
}
return;
}
RequestMapping methodRequestMapping = method.getDeclaredAnnotation(RequestMapping.class);
if(methodRequestMapping==null){
return;
}
RequestMethod[] requestMethods = methodRequestMapping.method();
if(requestMethods.length>0){
api.methods = new String[requestMethods.length];
for(int i=0;i apiParameterList = new ArrayList<>();
List parameterEntityNameList = new ArrayList<>();
for(int i=0;i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy