本文整理汇总了Java中org.springframework.core.MethodParameter.getParameterName方法的典型用法代码示例。如果您正苦于以下问题:Java MethodParameter.getParameterName方法的具体用法?Java MethodParameter.getParameterName怎么用?Java MethodParameter.getParameterName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.core.MethodParameter
的用法示例。
在下文中一共展示了MethodParameter.getParameterName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: contributeMethodArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
Class<?> paramType = parameter.getParameterType();
if (Map.class.isAssignableFrom(paramType) || MultipartFile.class.equals(paramType) ||
"javax.servlet.http.Part".equals(paramType.getName())) {
return;
}
RequestParam annot = parameter.getParameterAnnotation(RequestParam.class);
String name = StringUtils.isEmpty(annot.value()) ? parameter.getParameterName() : annot.value();
if (value == null) {
builder.queryParam(name);
}
else if (value instanceof Collection) {
for (Object element : (Collection<?>) value) {
element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
builder.queryParam(name, element);
}
}
else {
builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
}
}
示例2: getHttpEntityType
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
private Class<?> getHttpEntityType(MethodParameter methodParam) {
Assert.isAssignable(HttpEntity.class, methodParam.getParameterType());
ParameterizedType type = (ParameterizedType) methodParam.getGenericParameterType();
if (type.getActualTypeArguments().length == 1) {
Type typeArgument = type.getActualTypeArguments()[0];
if (typeArgument instanceof Class) {
return (Class<?>) typeArgument;
}
else if (typeArgument instanceof GenericArrayType) {
Type componentType = ((GenericArrayType) typeArgument).getGenericComponentType();
if (componentType instanceof Class) {
// Surely, there should be a nicer way to do this
Object array = Array.newInstance((Class<?>) componentType, 0);
return array.getClass();
}
}
}
throw new IllegalArgumentException(
"HttpEntity parameter (" + methodParam.getParameterName() + ") is not parameterized");
}
示例3: contributeMethodArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
Class<?> paramType = parameter.getNestedParameterType();
if (Map.class.isAssignableFrom(paramType)) {
return;
}
WxApiParam wxApiParam = parameter.getParameterAnnotation(WxApiParam.class);
String name = (wxApiParam == null || StringUtils.isEmpty(wxApiParam.name()) ? parameter.getParameterName() : wxApiParam.name());
WxAppAssert.notNull(name, "请添加编译器的-parameter或者为参数添加注解名称");
if (value == null) {
if (wxApiParam != null) {
if (!wxApiParam.required() || !wxApiParam.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
return;
}
}
builder.queryParam(name);
} else if (value instanceof Collection) {
for (Object element : (Collection<?>) value) {
element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
builder.queryParam(name, element);
}
} else {
builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
}
}
示例4: getParameterName
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
public static String getParameterName(Method method, int paramIdx) {
MethodParameter methodParameter = new MethodParameter(method, paramIdx);
methodParameter.initParameterNameDiscovery(parameterNameDiscoverer);
String paramName = methodParameter.getParameterName();
if (paramName == null) {
// 小于jdk8的场景中,即使有debug参数,也无法对着interface获取参数名,此时直接使用arg + paramIndex来表示
paramName = "arg" + paramIdx;
}
return paramName;
}
示例5: resolveArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
throws Exception {
String body = getRequestBody(webRequest);
String value = parameter.getParameterAnnotation(JsonParameter.class).value();
if (StringUtils.isBlank(value)) {
value = parameter.getParameterName();
}
return parameterParser.parse(body, value, parameter);
}
示例6: updateNamedValueInfo
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
/**
* Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
*/
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
String name = info.name;
if (info.name.length() == 0) {
name = parameter.getParameterName();
Assert.notNull(name, "Name for argument type [" + parameter.getParameterType().getName()
+ "] not available, and parameter name information not found in class file either.");
}
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
return new NamedValueInfo(name, info.required, defaultValue);
}
示例7: readWithMessageConverters
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object readWithMessageConverters(MethodParameter methodParam, HttpInputMessage inputMessage, Class<?> paramType)
throws Exception {
MediaType contentType = inputMessage.getHeaders().getContentType();
if (contentType == null) {
StringBuilder builder = new StringBuilder(ClassUtils.getShortName(methodParam.getParameterType()));
String paramName = methodParam.getParameterName();
if (paramName != null) {
builder.append(' ');
builder.append(paramName);
}
throw new HttpMediaTypeNotSupportedException(
"Cannot extract parameter (" + builder.toString() + "): no Content-Type found");
}
List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
if (this.messageConverters != null) {
for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
if (messageConverter.canRead(paramType, contentType)) {
if (logger.isDebugEnabled()) {
logger.debug("Reading [" + paramType.getName() + "] as \"" + contentType
+"\" using [" + messageConverter + "]");
}
return messageConverter.read((Class) paramType, inputMessage);
}
}
}
throw new HttpMediaTypeNotSupportedException(contentType, allSupportedMediaTypes);
}
示例8: getRequiredParameterName
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
private String getRequiredParameterName(MethodParameter methodParam) {
String name = methodParam.getParameterName();
if (name == null) {
throw new IllegalStateException(
"No parameter name specified for argument of type [" + methodParam.getParameterType().getName() +
"], and no parameter name information found in class file either.");
}
return name;
}
示例9: resolveArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
String body = getRequestBody(webRequest);
String arg = parameter.getParameterAnnotation(JsonArg.class).value();
if (StringUtils.isEmpty(arg)) {
arg = parameter.getParameterName();
}
return JsonPath.parse(body).read(arg, parameter.getParameterType());
}
示例10: contributeMethodArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) {
return;
}
WxApiPath wx = parameter.getParameterAnnotation(WxApiPath.class);
String name = (wx != null && !StringUtils.isEmpty(wx.value()) ? wx.value() : parameter.getParameterName());
WxAppAssert.notNull(name, "请添加编译器的-parameter或者为参数添加注解名称");
value = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value);
uriVariables.put(name, value);
}
示例11: getMethodArgumentValues
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
private Object[] getMethodArgumentValues(WampMessage message, List<Object> arguments,
Map<String, Object> argumentsKw) throws Exception {
MethodParameter[] parameters = getMethodParameters();
Object[] args = new Object[parameters.length];
int argIndex = 0;
for (int i = 0; i < parameters.length; i++) {
MethodParameter parameter = parameters[i];
parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
if (this.argumentResolvers.supportsParameter(parameter)) {
try {
args[i] = this.argumentResolvers.resolveArgument(parameter, message);
continue;
}
catch (Exception ex) {
if (this.logger.isDebugEnabled()) {
this.logger.debug(
getArgumentResolutionErrorMessage("Failed to resolve", i),
ex);
}
throw ex;
}
}
if (arguments != null && arguments.size() > argIndex) {
args[i] = convert(parameter, arguments.get(argIndex));
if (args[i] != null) {
argIndex++;
continue;
}
}
if (argumentsKw != null) {
String paramName = parameter.getParameterName();
if (paramName != null) {
Object arg = argumentsKw.get(paramName);
if (arg != null) {
args[i] = convert(parameter, arg);
continue;
}
}
}
if (args[i] == null) {
throw new MethodArgumentResolutionException(message, parameter,
getArgumentResolutionErrorMessage("No suitable resolver for", i));
}
}
return args;
}