本文整理匯總了Java中org.springframework.web.bind.annotation.ModelAttribute.value方法的典型用法代碼示例。如果您正苦於以下問題:Java ModelAttribute.value方法的具體用法?Java ModelAttribute.value怎麽用?Java ModelAttribute.value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.bind.annotation.ModelAttribute
的用法示例。
在下文中一共展示了ModelAttribute.value方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addReturnValueAsModelAttribute
import org.springframework.web.bind.annotation.ModelAttribute; //導入方法依賴的package包/類
protected final void addReturnValueAsModelAttribute(Method handlerMethod, Class<?> handlerType,
Object returnValue, ExtendedModelMap implicitModel) {
ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
String attrName = (attr != null ? attr.value() : "");
if ("".equals(attrName)) {
Class<?> resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
}
implicitModel.addAttribute(attrName, returnValue);
}
示例2: getNameForReturnValue
import org.springframework.web.bind.annotation.ModelAttribute; //導入方法依賴的package包/類
/**
* Derive the model attribute name for the given return value using
* one of the following:
* <ol>
* <li>The method {@code ModelAttribute} annotation value
* <li>The declared return type if it is other than {@code Object}
* <li>The actual return value type
* </ol>
* @param returnValue the value returned from a method invocation
* @param returnType the return type of the method
* @return the model name, never {@code null} nor empty
*/
public static String getNameForReturnValue(Object returnValue, MethodParameter returnType) {
ModelAttribute annot = returnType.getMethodAnnotation(ModelAttribute.class);
if (annot != null && StringUtils.hasText(annot.value())) {
return annot.value();
}
else {
Method method = returnType.getMethod();
Class<?> resolvedType = GenericTypeResolver.resolveReturnType(method, returnType.getContainingClass());
return Conventions.getVariableNameForReturnType(method, resolvedType, returnValue);
}
}
示例3: getNameForParameter
import org.springframework.web.bind.annotation.ModelAttribute; //導入方法依賴的package包/類
/**
* Derives the model attribute name for a method parameter based on:
* <ol>
* <li>The parameter {@code @ModelAttribute} annotation value
* <li>The parameter type
* </ol>
* @return the derived name; never {@code null} or an empty string
*/
public static String getNameForParameter(MethodParameter parameter) {
ModelAttribute annot = parameter.getParameterAnnotation(ModelAttribute.class);
String attrName = (annot != null) ? annot.value() : null;
return StringUtils.hasText(attrName) ? attrName : Conventions.getVariableNameForParameter(parameter);
}