类 ModelHandler
java.lang.Object
cn.taketoday.web.handler.method.ModelHandler
Assist with initialization of the
Model before controller method
invocation and with updates to it after the invocation.
On initialization the model is populated with attributes temporarily stored
in the session and through the invocation of @ModelAttribute methods.
On update model attributes are synchronized with the session and also
BindingResult attributes are added if missing.
- 从以下版本开始:
- 4.0 2022/4/8 23:00
- 作者:
- Rossen Stoyanchev, Harry Yang
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明private static final cn.taketoday.logging.Logger(专用程序包) final ControllerMethodResolver -
构造器概要
构造器构造器说明ModelHandler(ControllerMethodResolver methodResolver) Create a new instance with the given@ModelAttributemethods. -
方法概要
修饰符和类型方法说明findSessionAttributeArguments(SessionAttributesHandler sessionAttrHandler, HandlerMethod handlerMethod) Find@ModelAttributearguments also listed as@SessionAttributes.private ArrayList<ModelHandler.ModelMethod>getModelMethods(HandlerMethod handlerMethod) static StringgetNameForParameter(cn.taketoday.core.MethodParameter parameter) Derive the model attribute name for the given method parameter based on a@ModelAttributeparameter annotation (if present) or falling back on parameter type based conventions.static StringgetNameForReturnValue(Object returnValue, HandlerMethod handler) Derive the model attribute name for the given return value.private ModelHandler.ModelMethodgetNextModelMethod(BindingContext container, ArrayList<ModelHandler.ModelMethod> modelMethods) voidinitModel(RequestContext request, BindingContext container, HandlerMethod handlerMethod) Populate the model in the following order: Retrieve "known" session attributes listed as@SessionAttributes.private voidinvokeModelAttributeMethods(RequestContext request, BindingContext container, ArrayList<ModelHandler.ModelMethod> modelMethods) Invoke model attribute methods to populate the model.private booleanisBindingCandidate(String attributeName, Object value, SessionAttributesHandler sessionAttrHandler) Whether the given attribute requires aBindingResultin the model.private voidupdateBindingResult(RequestContext request, BindingContext bindingContext, cn.taketoday.ui.ModelMap model, SessionAttributesHandler sessionAttributesHandler) AddBindingResultattributes to the model for attributes that require it.voidupdateModel(RequestContext request, BindingContext container, Class<?> handlerMethod) Promote model attributes listed as@SessionAttributesto the session.
-
字段详细资料
-
log
private static final cn.taketoday.logging.Logger log -
methodResolver
-
-
构造器详细资料
-
ModelHandler
Create a new instance with the given@ModelAttributemethods.
-
-
方法详细资料
-
initModel
public void initModel(RequestContext request, BindingContext container, HandlerMethod handlerMethod) throws Throwable Populate the model in the following order:- Retrieve "known" session attributes listed as
@SessionAttributes. - Invoke
@ModelAttributemethods - Find
@ModelAttributemethod arguments also listed as@SessionAttributesand ensure they're present in the model raising an exception if necessary.
- Retrieve "known" session attributes listed as
-
getModelMethods
-
invokeModelAttributeMethods
private void invokeModelAttributeMethods(RequestContext request, BindingContext container, ArrayList<ModelHandler.ModelMethod> modelMethods) throws Throwable Invoke model attribute methods to populate the model. Attributes are added only if not already present in the model.- 抛出:
Throwable
-
getNextModelMethod
private ModelHandler.ModelMethod getNextModelMethod(BindingContext container, ArrayList<ModelHandler.ModelMethod> modelMethods) -
findSessionAttributeArguments
private List<String> findSessionAttributeArguments(SessionAttributesHandler sessionAttrHandler, HandlerMethod handlerMethod) Find@ModelAttributearguments also listed as@SessionAttributes. -
updateModel
public void updateModel(RequestContext request, BindingContext container, Class<?> handlerMethod) throws Throwable Promote model attributes listed as@SessionAttributesto the session. AddBindingResultattributes where necessary. -
updateBindingResult
private void updateBindingResult(RequestContext request, BindingContext bindingContext, cn.taketoday.ui.ModelMap model, SessionAttributesHandler sessionAttributesHandler) throws Throwable AddBindingResultattributes to the model for attributes that require it.- 抛出:
Throwable
-
isBindingCandidate
private boolean isBindingCandidate(String attributeName, Object value, SessionAttributesHandler sessionAttrHandler) Whether the given attribute requires aBindingResultin the model. -
getNameForParameter
Derive the model attribute name for the given method parameter based on a@ModelAttributeparameter annotation (if present) or falling back on parameter type based conventions.- 参数:
parameter- a descriptor for the method parameter- 返回:
- the derived name
- 另请参阅:
-
Conventions.getVariableNameForParameter(MethodParameter)
-
getNameForReturnValue
Derive the model attribute name for the given return value. Results will be based on:- the method
ModelAttributeannotation value - the declared return type if it is more specific than
Object - the actual return value type
- 参数:
returnValue- the value returned from a method invocationhandler- a descriptor for the method- 返回:
- the derived name (never
nullor empty String)
- the method
-