问题
I'm thinking about validation of my web application. Here is to approaches. 1) Make validation with Spring Validator implement interface 2)Use JSR-303 on domain model.
First approach looks more nicer like I can use messages to render errors on any languages and can do more complex logic. But hibernate docs shows that JSR-303 more preferable as for hibernate, I'm thinking I already identified my entity with annotation mapping and put more for validation JSR 303 it won't be much? Maybe I should do it on both if it possible.
What you suggest? Thank you
回答1:
Personally, I think that web (or input) validation is very, different from persistence validation. Often they will be the same, but often they won't, unless your app only takes data and puts in a DB without doing anything else apart from validation.
If you mingle your persistence and input validation, your domain model will suffer as you'll try to make it a mix of presentation+domain model, and changes in one will affect the other (bye, bye locality).
Mixing the validations might be ok on a very simple application or if you're building a "naked objects" solution (in which case the input MUST be the domain).
来源:https://stackoverflow.com/questions/17497302/validation-where-to-organize-in-web-app-for-more-efficient-way