What is the model key for an Errors object in Spring MVC?
In my Spring MVC based we开发者_StackOverflow中文版b-app, I'm manually creating an Errors/BindingResult object after manually validating one of my domain objects. I can add my domain object into the Model by doing the obvious:
model.addAttribute("myObject", myObject);
After I do validation and have created an Errors/BindingResult object, under which key should I add that to the model?
Note: I can't use the automatic validation provided by @Valid and bind my domain and errors object at the method level. I really do need to know how to do this manually.
The BindingResult
for a given model is added to the model map using keys constructed using a combination of BindingResult.MODEL_KEY_PREFIX
and the model name. if you have a dig through the source code (for example in HandlerMethodInvoker.updateModelAttributes()
), you can see how it's used.
It's a bit risky, though, this implementation detail may change in future versions of Spring.
精彩评论