How to handle DTOs for Request, Response and Entities in Spring MVC

I'm a little bit unsure about how to design a complex Spring MVC application in the best way. The problem is related to a usermanagement system. My UserVO implements the UserDetails interface of Spring.

But for request and response only a special part of information is needed. In the request it should be allowed to send the password in order to change it. But flags like 'enabled', 'expired', 'locked' should obviously not be changable by the user. On the other side this information should be displayed to the user, so must be included in the Response. The password is never send to the client.

I started with using the JsonIgnore and JsonAttribute Annotations on setter- and getter. But as the flags are boolean they are persisted with the default value 'false' every time I update.

Possible solution: Writing a DTO for response as well as for the request and using the ObjectMapper of Spring to persist them. Is this the right approach? I would feel more comfortable if I could just work with my VOs and set some magic annotations if you know what I mean ;)

Answers


You probably need a form-backing bean. You will find a ton of examples on internet.

EDIT :

Example with user. Your form contains the username, a field to change the password and a field to reconfirm the password. The username is in you User POJO wich contains all the data relative to your user.

To catch the password and password confirm from your form (and all other data that you expose from your User POJO you need a form-backing bean).

public class UserBacking {

  private String newPsw;

  private String confirmPsw;

  private User user;
}

In your form

<form:form action="${postUrl}" commandName="userBacking " method="POST">
   <!-- Fields goes here -->
</form>

In your Controller, your method will receive as ModelAttribute the UserBacking object.


Need Your Help

usort(): Array was modified by the user comparison function

php usort

I have a web application that runs fine on our Linux servers but when running on Mac OS with the Zend Community Edition Server using PHP 5.3 we get the error:

How do you make changes from a new windowManager window?

javascript tinymce tinymce-4

I'm fairly new to JavaScript, so I'm learning as I'm doing things. On my internship I was asked to adjust a WYSIWYG html editor so it can be used with e-mails. I'm using placeholders to later be re...