Validation where to organize in web app for more efficient way

两盒软妹~` 提交于 2020-01-05 10:08:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!