当前位置: 首页>>代码示例>>Java>>正文


Java ModelAttribute.value方法代码示例

本文整理汇总了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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:HandlerMethodInvoker.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:ModelFactory.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:ModelFactory.java


注:本文中的org.springframework.web.bind.annotation.ModelAttribute.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。