本文整理汇总了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);
}