Java development thinking of POJO and DAO

Java development thinking of POJO and DAO

 

POJO development is collectively DO, DTO and VO and the like.

DO is an abbreviation of data object, the data object is the meaning, and generally correspond to tables in the database. It will be placed domain package. If you are using jpa development, the DO's attributes are @Id, @Column, @OneToMany, @OneToOne, @ManyToMany and @mappBy notes and other modifications are made to establish the mapping relationships between data objects with database tables, as well as the association between tables relationship. If you use mybatis development, you do not need to comment modification, only simple Java objects can be.

DAO is an acronym for data access object, and object data access meaning. If jpa development, can be placed in the repository or dao package, and is in the form of an interface, the interface repository need only to extend jpa provided and can add custom methods, jpa provided with curd and pagerepository curdrepository of interfaces, with to simplify common operations. If mybatis development, generally placed mapper package, the same interface type, interface @Select, @Update, @Insert, @Delete other modified annotation, handwritten annotations in complete SQL CRUD other common operations.

DTO is an abbreviation for data transfer object, meaning that the data transfer object, the package will be placed dto used in the service layer, the service layer will generally call a method defined in the DAO DO acquisition target, after completion of service logic, if the need to return the object , it will be converted to an object or a combination object transmission DTO outwardly. Conversion method generally employed copyproperties BeanUtils class spring replication properties provided by the DTO DO object to object.

VO is the abbreviation for the view object, a view object means, for displaying data to the user, with the controller layer, transmission controller object outward, the controller will call the general method of obtaining the service layer DTO class object, and then converted to VO object is returned to the calling terminal.

DO to DTO, VO and then transformed, partly in order to return data to the calling terminal, the other is for safety, do not put sensitive information is returned to the calling terminal.

Guess you like

Origin blog.csdn.net/songxiugongwang/article/details/90203941