I have started a Spring Rest project as a beginner. Most of my entities have more than 15-20 attributes and not all attributes are required on the UI layer.
I am considering using DTO for the following reasons:
- To minimise the un-necessary information to be sent for information privacy reasons.
- To reduce the size of the json string for performance.
- Different UI using the same entity may have different business validations (i.e. mandatory/optional fields). I can create 2 DTO for the same entity and annotate the validations accordingly.
I am considering using DTO to merge multiple entities together, hide/show certain information for certain UI based on the roles, but I have to "split/copy" the DTO information back to different entities when I need to persist the details.
Staff - Able to view the performance appraisal and comments by the next level manager.
Manager - Able to enter comments for the performance appraisal, and indicate the pay increment for the staff (This is not shown in the staff's UI), but not able to view the staff's current pay.
HR - Able to view all the details for all UI.
I would like to find out if there is a better way to handle such concerns or am I heading the right direction for my project?
Ref: http://www.baeldung.com/entity-to-and-from-dto-for-a-java-spring-application
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…