Spring MVC: should service layer be returning operation specific DTO's ?

Posted by arrages on Stack Overflow See other posts from Stack Overflow or by arrages
Published on 2010-04-14T03:20:35Z Indexed on 2010/04/14 3:23 UTC
Read the original article Hit count: 247

Filed under:
|
|
|
|

In my Spring MVC application I am using DTO in the presentation layer in order to encapsulate the domain model in the service layer. The DTO's are being used as the spring form backing objects.

hence my services look something like this:

userService.storeUser(NewUserRequestDTO req);

The service layer will translate DTO -> Domain object and do the rest of the work.

Now my problem is that when I want to retrieve a DTO from the service to perform say an Update or Display I can't seem to find a better way to do it then to have multiple methods for the lookup that return different DTO's like...

EditUserRequestDTO userService.loadUserForEdit(int id);

DisplayUserDTO userService.loadUserForDisplay(int id);

but something does not feel right about this approach. The reason do have separate DTO's is that DisplayUserDTO is strongly typed to be read only and also there are many properties of user that are entities from a lookup table in the db (like city and state) so the DisplayUserDTO would have the string description of the properties while the EditUserRequestDTO will have the id's that will back the select drop down lists in the forms.

What do you think?

thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about spring