Invoke global, then local @InitBinder/@ModelAttribute

@InitBinder and @ModelAttribute methods in @ControllerAdvice classes
are now invoked first, allowing any such methods in the @Controller
class to override them.

Issue: SPR-10419
This commit is contained in:
Rossen Stoyanchev
2013-05-10 10:42:42 -04:00
parent 640555194b
commit 78fcd28389
2 changed files with 19 additions and 10 deletions

View File

@@ -181,7 +181,8 @@ public class RequestMappingHandlerAdapterTests {
this.handlerAdapter.afterPropertiesSet();
ModelAndView mav = this.handlerAdapter.handle(this.request, this.response, handlerMethod);
assertEquals("globalAttrValue", mav.getModel().get("globalAttr"));
assertEquals("lAttr1", mav.getModel().get("attr1"));
assertEquals("gAttr2", mav.getModel().get("attr2"));
}
@@ -200,6 +201,11 @@ public class RequestMappingHandlerAdapterTests {
@SuppressWarnings("unused")
private static class SimpleController {
@ModelAttribute
public void addAttributes(Model model) {
model.addAttribute("attr1", "lAttr1");
}
public String handle() {
return null;
}
@@ -227,7 +233,8 @@ public class RequestMappingHandlerAdapterTests {
@ModelAttribute
public void addAttributes(Model model) {
model.addAttribute("globalAttr", "globalAttrValue");
model.addAttribute("attr1", "gAttr1");
model.addAttribute("attr2", "gAttr2");
}
}