返回信息流In Spring Web MVC you can use any object as a command or form-backing object; you do not need to implement a framework-specific interface or base class. Spring’s data binding is highly flexible: for example, it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. Thus you do not need to duplicate your business objects' properties as simple, untyped strings in your form objects simply to handle invalid submissions, or to convert the Strings properly. Instead, it is often preferable to bind directly to your business objects.
这是一条镜像帖。来源:北邮人论坛 / java / #53076同步于 2016/9/20
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
这段spring MVC文档里的话无法完全理解,有大神能举例说明一下
wislov
2016/9/20镜像同步13 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
spring的数据绑定是动态的,你可以用任何对象作为命令对象,或者表单的下层对象。你不用让你的业务对象实现Spring提供的任何接口。Spring的数据绑定非常灵活:比如:类型不匹配,是验证错误(应该是表单验证),而不是系统错误(我也不知道“系统错误”是什么意思,但大概知道Spring会在表单验证的同时做数据类型转换)。因为这个,你不需要仅仅为了处理输入错误,而修改你的业务对象,增加额外的属性,把原属性的类型变成String。Spring也鼓励你直接(把表单)绑定到业务对象里去。