Turn from: http://blog.csdn.net/visant
This article is mainly about the use of the DTO and the benefits it brings. The first thing to understand is what a DTO is.
The DTO is the abbreviation for the data transfer object (data Transfer object). DTO mode, refers to the data encapsulated into ordinary JavaBeans, in the Java EE multiple levels between the transmission. A dto resembles a messenger, which is a message in a synchronization system. The JavaBeans can be a model of data models.
In traditional programming, we are generally the foreground request data, sent to the webservice, and then webservice to the database to make a request, get the data, and then a layer back; the model is as follows:
This compares the original request method to bring the shortcoming to have many, the request consumes certain network resources repeatedly, slows down the efficiency. If you return the entire entity class at once, you may also cause a leak in the database table structure.
After the DTO model is adopted, the entire process is different:
The benefits of this are:
1. Based on the existing class code, it is convenient to construct a Dto object without having to analyze it again.
2. Reduce the number of requests, greatly improve efficiency.
3. On-Demand organization DTO object, the page needs the field I just organize, do not need I do not organize, you can avoid the transfer of the entire table field, to some extent, improve security.
Talk about usage in combination with personal development experience:
In general, we use the Dto class to inherit the entity entity class, put some business fields in the Dto class, and provide a get, set method. When we use fields that do not exist in the database in the business logic layer or the interaction layer, we need to place these fields in the Dto class, which is equivalent to some of the processed database fields, and the real meaning is to facilitate data interaction and improve efficiency.