When using JAXB, software developers only need to write a series of descriptive information in the. Is not it simple? Of course, this still has third-party tools to help us complete this.
A more famous tool is dozer. It is also very simple to use DOZER, indicating two types that need to be converted in its configuration file:. At runtime, Dozer uses reflection to match and assign each of these two types of properties. If the properties of different names in both types, the software developers can explicitly specify the mutual matching properties:.
Under the aid of these tools, it has become simpler for the system to add DTO. Of course, if you use custom conversion logic in Dozer, software developers also need to update the corresponding conversion logic.
Only data is included in the DTO, and no behavior is included. But don't do it. This often causes you into a trap of anemia model. In the server's business logic implementation and client's page logic, we sometimes need to specify the operational logic of these data. From the perspective of object-oriented design, some logic should actually be defined in these types. But because DTO itself does not define these logic, we need to define them outside of these types, such as defining a series of secondary functions for these types in a helper class.
A simplest example is an inspection of data validity. For example, in a Person class, we use a integer data to record the age of the character:. So in business logic, we need to check if this domain is set to negative. As a variant, we need to write a secondary class to complete this feature.
But as this requirement is increasing, management of these auxiliary functions will be more difficult. At this point you will completely fall into the trap of anemia model. That is, the main responsibility of the DTO is to transmit data, but it is not good at, or even not suitable for representing a complex concept in business logic.
A complex concept is often associated with some reusable complex logic, but this is exactly what DTO can't do. In order to solve this problem, we can add a business logic performance on the server, which is BO Business Object. When all business processes are completed and need to be sent to customers, BO will be converted to DTO for transmission. And at the client, we can also introduce a new layer of data performance that is more suitable for page logic.
Sometimes, some class libraries provide a simpler way, such as the Mixin functionality provided by Yui and ExtJS. Of course, the software developers need to carefully consider the balance between the workload required to add these models before adding these data.
Some people may see this title. Yes, there is no comparability of both. In fact, DAO is a standard mode for organizing database access logic. That is, it should be a common method of using a series of data accesss such as Repository mode.
Since this paper focuses on data, DAO itself can also be used as an independent blog, so it will not be described in detail herein.
DAO layer: The DAO layer is mainly working for data persistence, and some tasks responsible for contacting the database are packaged here. Class, then call this interface in the module to perform the processing of data services, without concern which type of specific implementation classes of this interface, appear very clear, DAO layer data source configuration, and parameters for database connections Configure in the Spring configuration file.
Service layer: The Service layer is mainly responsible for the logical application design of the business module. It is also the first design interface, and then design the class that it implements it, then configure its implementation in the Spring configuration file. This way we can call the service interface in the application to perform business processing.
Service layer business implementation, specific to the interface that is defined to the defined DAO layer, and the service logic of the package service layer facilitates the independence and reuse of the general business logic, and the program is very simple. Controller layer: The Controller layer is responsible for the control of the specific business module process. In this layer, you want to call the server layer interface to control the business process, the control configuration is also performed in the Spring configuration file, for specific business processes, will There are different controllers, and the process can be abstracted in the process, which is designed to design a sub-unit process module that can be reused, which not only makes the program structure clear, but also greatly reduces the amount of code.
The view layer is relatively close to the control layer and need two to cooperate with work. The View layer is mainly responsible for the representation of the front desk JSP page. The two levels of the DAO layer can be developed separately. The mutual coupling is very low, which can be carried out independently. Such a model is particularly advantageous during the development of large projects, and the controller, the View layer is compared to the coupling degree High, thus to be combined, but it can also be seen as a whole independent of the first two layers.
In this way, we only need to know the definition of the interface before the layer and the layer, the calling interface can complete the required logic unit applications, everything is very clear and simple. The overall plan for DAO design needs and design, and the corresponding class corresponds. The method in the interface defined by the DAO layer is similar, which is determined by the operation of our DAO layer to database access, the operation of the database, we basically use new, updated, deleted, query and other methods.
Therefore, the DAO layer should basically cover the operations corresponding to these methods. In addition, some custom special methods for database access can be defined. After the DAO layer can be established, the service layer can be established, and the Service layer is under the Controller layer, so the service layer should call both the DAO layer interface, but also provide the interface to The class of the Controller layer is called, which is just in the position of an intermediate layer.
Each model has a service interface, each interface packages respective business processing methods, respectively. This is determined by the demand logic we define.
The DAO layer is basically universal after abstraction, so we can define the relevant method when defining the DAO layer, this benefit is that it is not necessary to modify the DAO layer when it is expanded to Service.
Improve the scalability of the program. Author: Cat Qi Source: cnblogs. Since different projects and developers have different nam Primary key generation strategy sequence database side native database side uuid The terminal automatically assigns a value to generate a bit hexadecimal number The entity class needs to change the Deposition of the sediment: bean, javabean, pojo, vo, po, ejb, etc.
Introduction If you want everyone to have such a confusion, the more you get in touch, but you will have a contrast and in-depth According to the standard: Each field in Entity, corresponds to the database Every field in Vo is corresponding to your front page. Value Object Programmer All technical sharing website that all programmers love.
In actual use, what is considered to be correct and not important, the key is the need for your own project in practical applications 5. TO Transfer Object , data transfer object Objects transmitted between applications Different TIE relationships In J2EE, several objects often mentioned, understanding their meaning helps us better understand the object-oriented design thinking.
DTO - Core data in service implementation In an implementation of a web service, we often need to access the database and display the data obtained from the database in the user page. Why DTO? Even, we can make things more complex: In the above figure, we showcase the possible forms of data that may exist in a system.
When transferring to the client, these data may be different from Mo, so it is DTO: Let us now enlarge the data access layer to see where MO is located in the data access layer: First, it is necessary to have a lot of ways to implement the data access layer, and the above picture is only a re-based implementation.
Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search. Relation between Item and Supplier is many to many. SupplierItem is intermediate table. DAO would be the java file where you define your query and get the results of the query call on the database.
The results from the query will be saved by setting them as values to the properties of a particular VO. So let us say that you will have to create another java file say ItemVO. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 5 years ago. Active 5 years ago. VO: Value Object , which is usually used for data transfer between business layers. Like PO, it only contains data. But it should be an abstracted business object, which can correspond to a table or not, depending on the needs of the business. The presentation layer object View Object mainly corresponds to the data object displayed on the display interface, and a VO object is used to encapsulate the object data required for the entire interface display.
Specifically, you can see an example on the Internet:. For example, a resume, with educational experience, work experience, social relations and so on. When dealing with business logic in this way, we can deal with BO. DTO: Data Transfer Object , is a software application system that transfers data between design patterns.
The data transmission goal is often the data access object to retrieve data from the database.
0コメント