當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。