我已经定义了一个方法getuserData:
@RequestMapping(value = "/myRestApi",method = RequestMethod.GET)
public @ResponseBody Map<String, MyClass1> getUserData(@RequestParam(value = "xyz1",
required = false) List<String> input1,
@RequestParam(value = "xyz2",
required = true) String input2,
@RequestParam(value = "xyz3",
required = false,
defaultValue = "COMPLETE") MyClass2 input3)
throws Exception
一个拦截器,用于扩展HandlerInterceptorAdapter的类中的相应请求。
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String method = request.getMethod();
String requestURL = request.getRequestURL().toString();
String remoteAddr = request.getRemoteAddr();
if (handler instanceof HandlerMethod) {
ArrayList<String> listOfParamNamesInMethodSignature = new ArrayList<>();
HandlerMethod handlerMethod = ((HandlerMethod) handler);
for (MethodParameter param : handlerMethod.getMethodParameters()) {
String name = param.getParameterName();
listOfParamNamesInMethodSignature.add(param.getParameterName());
}
List<String> listOfParamNamesInRequest1 = new ArrayList<String>(request.getParameterMap().keySet());
if(listOfParamNamesInRequest1 != null && listOfParamNamesInMethodSignature.containsAll(listOfParamNamesInRequest1))
return true;
}
}
现在,如果有人调用API,例如:/ myRestApi?xyz1 = fname,lname&amp; xyz2 = address
然后在处理程序中,我想获取API中传递的参数名称列表以及Handler方法中最终将为API请求提供服务的参数名称列表。
现在给出这个代码,我能够获得API请求中传递的参数名称(xyz1,xyz2),但是无法获取参数名称(xyz1,xyz2,xyz3)。 Handler方法,拦截器中的getUserData()。只有我在拦截器中获得的方法的信息才是它的名字,getUserData !!
请你帮我弄清楚我是否在这里遗漏了什么?