@ModelAttributeメソッドを特定のハンドラーメソッドに対してのみ呼び出し、1つのハンドラーメソッドの呼び出しに対してのみコマンドオブジェクトを提供することは可能ですか?特定のコントローラー内のハンドラーメソッドごとではありませんか?Spring Web-Portlet MVCを使用していますが、同じである必要があります...
これは、1つのコントローラー内のハンドラーメソッド呼び出しごとにこのforループが呼び出され、ビューに送信される各リクエストにimplicitModelが提供されるためです。
for (Method attributeMethod : this.methodResolver.getModelAttributeMethods()) {
Method attributeMethodToInvoke = BridgeMethodResolver.findBridgedMethod(attributeMethod);
Object[] args = resolveHandlerArguments(attributeMethodToInvoke, handler, webRequest, implicitModel);
if (debug) {
logger.debug("Invoking model attribute method: " + attributeMethodToInvoke);
}
String attrName = AnnotationUtils.findAnnotation(attributeMethodToInvoke, ModelAttribute.class).value();
if (!"".equals(attrName) && implicitModel.containsAttribute(attrName)) {
continue;
}
ReflectionUtils.makeAccessible(attributeMethodToInvoke);
Object attrValue = attributeMethodToInvoke.invoke(handler, args);
if ("".equals(attrName)) {
Class resolvedType = GenericTypeResolver.resolveReturnType(attributeMethodToInvoke, handler.getClass());
attrName = Conventions.getVariableNameForReturnType(attributeMethodToInvoke, resolvedType, attrValue);
}
if (!implicitModel.containsAttribute(attrName)) {
implicitModel.addAttribute(attrName, attrValue);
}
}