以下是我的方法:
@PreAuthorize("isAuthenticated() and hasPermission(#request, 'CREATE_REQUISITION')")
@RequestMapping(method = RequestMethod.POST, value = "/trade/createrequisition")
public @ResponseBody
void createRequisition(@RequestBody CreateRequisitionRO[] request,
@RequestHeader("validateOnly") boolean validateOnly) {
logger.debug("Starting createRequisition()...");
for (int i = 0; i < request.length; i++) {
CreateRequisitionRO requisitionRequest = request[i];
// FIXME this has to be removed/moved
requisitionRequest.setFundManager(requisitionRequest.getUserId());
// FIXME might have to search using param level as well
SystemDefault sysDefault = dbFuncs.references.systemDefault
.findByCompanyAndDivisionAndPortfolio(
userContext.getCompany(),
userContext.getDivision(),
requisitionRequest.getPortfolio());
requisitionRequest.setCustodianN(sysDefault.getCustodianN());
gateKeeper.route(requisitionRequest);
}
}
我可以在其中获得以下详细信息
1. @RequestMapping(method = RequestMethod.POST, value = "/trade/createrequisition")
2. void createRequisition(@RequestBody CreateRequisitionRO[] request,
@RequestHeader("validateOnly") boolean validateOnly)
(in thesecond one i am able to get the argument type like boolean etc)
我得到如下详细信息:
Class cls;
cls = Class.forName(obj.getName());
Method[] method = cls.getDeclaredMethods();
for (Method method2 : method) {
RequestMapping requestMappingAnnotation = method2.getAnnotation(RequestMapping.class); // gets the method which is maped with RequestMapping Annotation
requestMappingValues = requestMappingAnnotation.value(); // to get the url value
RequestMethod[] methods = requestMappingAnnotation.method(); // to get the request method type
requestingMethod = methods[0].name();
}
以同样的方式,当我尝试@RequestHeader
像下面这样我得到java.lang.NullPointerException
下面是我使用的代码片段
RequestHeader requestHeader = method2.getAnnotation(RequestHeader.class);
System.out.println("requestHeader : "+requestHeader.value());
我想要得到的是@RequestHeader("validateOnly")
这个注释包含的值。
编辑 :
感谢@NilsH,他始终支持所有的澄清,即使需要花费时间:
这就是我解决它的方法but the information will be available if the program is in debug mode
我用弹簧来做到这一点:
LocalVariableTableParameterNameDiscoverer lcl = new LocalVariableTableParameterNameDiscoverer();
parametersDefinedForMethod = lcl.getParameterNames(method2);
for (String params : parametersDefinedForMethod) {
System.out.println("Params : "+params);
}
请帮我完成这件事。
谢谢