java - Submitting / binding partial objects with spring mvc -


The Spring MVC binding mechanism is powerful, but now I have to face a trivial issue which I wonder how to solve:

< P> / P>
  • User JPA unit, which is also used for binding and validation (i.e. in all layers)
  • "Edit Profile "Page, that

Two ways I can think of:

  1. using the same object

  2. Then
  3. use
  4. Use the reflection utility (beanutils) to copy the presented object to the target object, but ignore null values ​​- that is, the fields are not deposited
  5. Introduce a new object, in which the required subsets of the field, and BeanUtils.copyProperties (..) are used in the unit To merge.

Option?

I've noticed that as soon as your web model starts to separate from its business layer in the function , It is best to use a visual layer object (a model object) to collect data or display data:

>
  public class com.myapp.domain.UserEntity {}  

Model object:

  public class com.myapp.somesite.web.SomeSiteUserModel {publicStatic SomeSiteUserModel {UserEntity userEntity} {... initialize Model ...} universal Nick UserEntity getModelObject () {... unit back ...}}  

Now all visual-based operations can stop processing of internal model objects, if it makes sense, otherwise It can adapt itself. Of course with this problem you will have to rewrite all the recipients and the setter for the institution (one issue that was to deal with me, which is disturbing) Unfortunately, this is a bit of an issue of Java language.


Comments