本文整理汇总了Java中org.springframework.core.MethodParameter.getParameterType方法的典型用法代码示例。如果您正苦于以下问题:Java MethodParameter.getParameterType方法的具体用法?Java MethodParameter.getParameterType怎么用?Java MethodParameter.getParameterType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.core.MethodParameter
的用法示例。
在下文中一共展示了MethodParameter.getParameterType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
/**
* Delegate to the {@link WebArgumentResolver} instance.
* @exception IllegalStateException if the resolved value is not assignable
* to the method parameter.
*/
@Override
public Object resolveArgument(
MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
throws Exception {
Class<?> paramType = parameter.getParameterType();
Object result = this.adaptee.resolveArgument(parameter, webRequest);
if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
throw new IllegalStateException(
"Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() +
"resolved to incompatible value of type [" + (result != null ? result.getClass() : null) +
"]. Consider declaring the argument type in a less specific fashion.");
}
return result;
}
示例2: 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));
}
}
示例3: resolveCookieValue
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
private Object resolveCookieValue(String cookieName, boolean required, String defaultValue,
MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
throws Exception {
Class<?> paramType = methodParam.getParameterType();
if (cookieName.length() == 0) {
cookieName = getRequiredParameterName(methodParam);
}
Object cookieValue = resolveCookieValue(cookieName, paramType, webRequest);
if (cookieValue == null) {
if (defaultValue != null) {
cookieValue = resolveDefaultValue(defaultValue);
}
else if (required) {
raiseMissingCookieException(cookieName, paramType);
}
cookieValue = checkValue(cookieName, cookieValue, paramType);
}
WebDataBinder binder = createBinder(webRequest, null, cookieName);
initBinder(handlerForInitBinderCall, cookieName, binder, webRequest);
return binder.convertIfNecessary(cookieValue, paramType, methodParam);
}
示例4: getPropertyType
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public synchronized Class<?> getPropertyType() {
if (this.propertyType == null) {
if (this.readMethod != null) {
this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
}
else {
MethodParameter writeMethodParam = getWriteMethodParameter();
if (writeMethodParam != null) {
this.propertyType = writeMethodParam.getParameterType();
}
else {
this.propertyType = super.getPropertyType();
}
}
}
return this.propertyType;
}
示例5: resolveArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter,
RestRequest request, RestDelegate handler) throws Exception {
Class<?> type = parameter.getParameterType();
if (RestRequest.class.isAssignableFrom(type)) {
return request;
} else if (RestDelegate.class.isAssignableFrom(type)) {
return handler;
} else if (ServerObjectExtensionContext.class.isAssignableFrom(type)) {
return request.getServerContext();
} else if (SecurityContext.class.isAssignableFrom(type)) {
return request.getSecurityContext();
} else if (Principal.class.isAssignableFrom(type)) {
return request.getSecurityContext().getUserPrincipal();
} else if (IServerObject.class.isAssignableFrom(type)) {
return request.getServerContext().getServerObject();
} else if (IServerEnvironment.class.isAssignableFrom(type)) {
return request.getServerContext().getServerEnvironment();
} else if (Map.class.isAssignableFrom(type)) {
return request.getAttributes();
}
return null;
}
示例6: resolveArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public final Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
Class<?> paramType = parameter.getParameterType();
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
Object arg = resolveName(namedValueInfo.name, parameter, webRequest);
if (arg == null) {
if (namedValueInfo.defaultValue != null) {
arg = resolveDefaultValue(namedValueInfo.defaultValue);
}
else if (namedValueInfo.required) {
handleMissingValue(namedValueInfo.name, parameter);
}
arg = handleNullValue(namedValueInfo.name, arg, paramType);
}
else if ("".equals(arg) && (namedValueInfo.defaultValue != null)) {
arg = resolveDefaultValue(namedValueInfo.defaultValue);
}
if (binderFactory != null) {
WebDataBinder binder = binderFactory.createBinder(webRequest, null, namedValueInfo.name);
arg = binder.convertIfNecessary(arg, paramType, parameter);
}
handleResolvedValue(arg, namedValueInfo.name, parameter, mavContainer, webRequest);
return arg;
}
示例7: supportsParameter
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
/**
* Supports the following:
* <ul>
* <li>@RequestParam-annotated method arguments.
* This excludes {@link Map} params where the annotation doesn't
* specify a name. See {@link RequestParamMapMethodArgumentResolver}
* instead for such params.
* <li>Arguments of type {@link MultipartFile}
* unless annotated with @{@link RequestPart}.
* <li>Arguments of type {@code javax.servlet.http.Part}
* unless annotated with @{@link RequestPart}.
* <li>In default resolution mode, simple type arguments
* even if not with @{@link RequestParam}.
* </ul>
*/
@Override
public boolean supportsParameter(MethodParameter parameter) {
Class<?> paramType = parameter.getParameterType();
if (parameter.hasParameterAnnotation(RequestParam.class)) {
if (Map.class.isAssignableFrom(paramType)) {
String paramName = parameter.getParameterAnnotation(RequestParam.class).value();
return StringUtils.hasText(paramName);
}
else {
return true;
}
}
else {
if (parameter.hasParameterAnnotation(RequestPart.class)) {
return false;
}
else if (MultipartFile.class.equals(paramType) || "javax.servlet.http.Part".equals(paramType.getName())) {
return true;
}
else if (this.useDefaultResolution) {
return BeanUtils.isSimpleProperty(paramType);
}
else {
return false;
}
}
}
示例8: getCollectionParameterType
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
private Class<?> getCollectionParameterType(MethodParameter parameter) {
Class<?> paramType = parameter.getParameterType();
if (Collection.class.equals(paramType) || List.class.isAssignableFrom(paramType)){
Class<?> valueType = GenericCollectionTypeResolver.getCollectionParameterType(parameter);
if (valueType != null) {
return valueType;
}
}
return null;
}
示例9: resolveName
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
/**
* 所有的转换都卸载了一起,有空可以分离为多个,抽象一层
*
* @param name
* @param parameter
* @param request
* @return dummy
* @throws Exception
*/
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
WxRequest wxRequest = WxWebUtils.getWxRequestFromRequest(servletRequest);
// 类型匹配,直接返回
if (parameter.getParameterType() == WxRequest.class) {
return wxRequest;
}
if (parameter.getParameterType() == WxRequest.Body.class) {
return wxRequest.getBody();
}
if (parameter.getParameterType() == WxUser.class) {
return wxUserManager.getWxUser(wxRequest.getBody().getFromUserName());
}
if (WxSession.class.isAssignableFrom(parameter.getParameterType())) {
return wxRequest.getWxSession();
}
if (WxRequestBody.class.isAssignableFrom(parameter.getParameterType())) {
return WxRequestBody.of((Class) parameter.getParameterType(), wxRequest.getBody());
}
// 如果可以获取用户则返回用户
Object user = getUser(parameter, wxRequest);
if (user != null) {
return user;
}
return wxRequest.getParameter(name);
}
示例10: handleReturnValue
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public RestResponse handleReturnValue(Object returnValue,
MethodParameter parameter, RestRequest request) throws Exception {
Class<?> type = parameter.getParameterType();
XmlRootElement xmlRootElement = type
.getAnnotation(XmlRootElement.class);
if (RestResponse.class.isAssignableFrom(type)) {
return (RestResponse) returnValue;
} else if (String.class.isAssignableFrom(type)) {
return new RestResponse(null,
JSONConverter.toByteArray((String) returnValue));
} else if (xmlRootElement != null) {
return new RestResponse(null,
objectMapper.writeValueAsBytes(returnValue));
} else if (IRecordSet.class.isAssignableFrom(type)) {
return new RestResponse(null,
objectMapper.writeValueAsBytes(returnValue));
} else if (IJSONObject.class.isAssignableFrom(type)) {
return new RestResponse(null,
JSONConverter.toByteArray(((IJSONObject) returnValue)
.toJSONString(null)));
} else if (IJSONArray.class.isAssignableFrom(type)) {
return new RestResponse(null,
JSONConverter.toByteArray(((IJSONArray) returnValue)
.toJSONString(null)));
}
throw new IllegalArgumentException(String.format(
"Cannot handle return value: %1$s", returnValue));
}
示例11: resolvePathVariable
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
private Object resolvePathVariable(String pathVarName, MethodParameter methodParam,
NativeWebRequest webRequest, Object handlerForInitBinderCall) throws Exception {
Class<?> paramType = methodParam.getParameterType();
if (pathVarName.length() == 0) {
pathVarName = getRequiredParameterName(methodParam);
}
String pathVarValue = resolvePathVariable(pathVarName, paramType, webRequest);
WebDataBinder binder = createBinder(webRequest, null, pathVarName);
initBinder(handlerForInitBinderCall, pathVarName, binder, webRequest);
return binder.convertIfNecessary(pathVarValue, paramType, methodParam);
}
示例12: 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);
}
示例13: resolveArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter,
RestRequest request, RestDelegate handler) throws Exception {
Class<?> type = parameter.getParameterType();
RequestParam annotation = parameter
.getParameterAnnotation(RequestParam.class);
String value = annotation.value();
JSONObject operationInput = new JSONObject(request.getOperationInput());
Object param = operationInput.opt(value);
return objectMapper.readValue(param != null ? param.toString() : null,
type);
}
示例14: resolveArgument
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter,
RestRequest request, RestDelegate handler) throws Exception {
Class<?> type = parameter.getParameterType();
BeanParam annotation = parameter
.getParameterAnnotation(BeanParam.class);
if (annotation != null) {
return objectMapper.readValue(request.getOperationInput(), type);
}
return null;
}
示例15: resolves
import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
@Override
public boolean resolves(MethodParameter parameter) {
Class<?> type = parameter.getParameterType();
return RestRequest.class.isAssignableFrom(type)
|| RestDelegate.class.isAssignableFrom(type)
|| ServerObjectExtensionContext.class.isAssignableFrom(type)
|| SecurityContext.class.isAssignableFrom(type)
|| Principal.class.isAssignableFrom(type)
|| IServerObject.class.isAssignableFrom(type)
|| IServerEnvironment.class.isAssignableFrom(type)
|| Map.class.isAssignableFrom(type);
}