本文整理匯總了Java中org.springframework.core.MethodParameter.getParameterIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodParameter.getParameterIndex方法的具體用法?Java MethodParameter.getParameterIndex怎麽用?Java MethodParameter.getParameterIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.core.MethodParameter
的用法示例。
在下文中一共展示了MethodParameter.getParameterIndex方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: DependencyDescriptor
import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
/**
* Create a new descriptor for a method or constructor parameter.
* @param methodParameter the MethodParameter to wrap
* @param required whether the dependency is required
* @param eager whether this dependency is 'eager' in the sense of
* eagerly resolving potential target beans for type matching
*/
public DependencyDescriptor(MethodParameter methodParameter, boolean required, boolean eager) {
Assert.notNull(methodParameter, "MethodParameter must not be null");
this.methodParameter = methodParameter;
this.declaringClass = methodParameter.getDeclaringClass();
this.containingClass = methodParameter.getContainingClass();
if (this.methodParameter.getMethod() != null) {
this.methodName = methodParameter.getMethod().getName();
this.parameterTypes = methodParameter.getMethod().getParameterTypes();
}
else {
this.parameterTypes = methodParameter.getConstructor().getParameterTypes();
}
this.parameterIndex = methodParameter.getParameterIndex();
this.required = required;
this.eager = eager;
}
示例2: getObjectBody
import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
private Object getObjectBody(WxApiMethodInfo wxApiMethodInfo, Object[] args) {
MethodParameter methodParameter = wxApiMethodInfo.getMethodParameters().stream()
.filter(p -> !BeanUtils.isSimpleValueType(p.getParameterType()) || p.hasParameterAnnotation(WxApiBody.class))
.findFirst().orElse(null);
if (methodParameter == null) {
throw new WxAppException("沒有可處理的參數");
}
// 不是簡單類型
if (!BeanUtils.isSimpleValueType(methodParameter.getParameterType())) {
// 暫時隻支持json
return args[methodParameter.getParameterIndex()];
}
if (args[methodParameter.getParameterIndex()] != null) {
return args[methodParameter.getParameterIndex()].toString();
} else {
return "";
}
}
示例3: getStringBody
import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
private String getStringBody(WxApiMethodInfo wxApiMethodInfo, Object[] args) {
MethodParameter methodParameter = wxApiMethodInfo.getMethodParameters().stream()
.filter(p -> BeanUtils.isSimpleValueType(p.getParameterType()) || p.hasParameterAnnotation(WxApiBody.class))
.findFirst().orElse(null);
if (methodParameter == null) {
throw new WxAppException("沒有可處理的參數");
}
// 不是簡單類型
if (!BeanUtils.isSimpleValueType(methodParameter.getParameterType())) {
try {
// 暫時隻支持json
return jsonConverter.writeValueAsString(args[methodParameter.getParameterIndex()]);
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
}
if (args[methodParameter.getParameterIndex()] != null) {
return args[methodParameter.getParameterIndex()].toString();
} else {
return "";
}
}
示例4: isBindExceptionRequired
import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
/**
* Whether to raise a {@link BindException} on validation errors.
* @param binder the data binder used to perform data binding
* @param parameter the method argument
* @return {@code true} if the next method argument is not of type {@link Errors}.
*/
protected boolean isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter) {
int i = parameter.getParameterIndex();
Class<?>[] paramTypes = parameter.getMethod().getParameterTypes();
boolean hasBindingResult = (paramTypes.length > (i + 1) && Errors.class.isAssignableFrom(paramTypes[i + 1]));
return !hasBindingResult;
}
示例5: handles
import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
@Override
public boolean handles(MethodParameter parameter) {
if (parameter.getParameterIndex() != -1) {
throw new IllegalArgumentException(
"Method parameter must be a return value.");
}
Class<?> type = parameter.getParameterType();
return RestResponse.class.isAssignableFrom(type)
|| IRecordSet.class.isAssignableFrom(type)
|| type.getAnnotation(XmlRootElement.class) != null
|| IRecordSet.class.isAssignableFrom(type)
|| IJSONObject.class.isAssignableFrom(type)
|| IJSONArray.class.isAssignableFrom(type);
}