Java deep understanding of DTO and how to use Dto__java

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.