Java implements interconversion operations such as pojo, dto, vo, etc. with the same attribute name and similar types
Applied to actual projects: 1.Interchange between thrift objects and dto 2.Transfer between pojo and dto 3.Transfer between pojo and vo 1. The core conversion tool class does not handle particularly complex types because the business scenarios have not been covered package littlehow.convert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.math.BigDecimal; import java.sql.Timestamp; import java.util.*; import java.util.concurrent.ConcurrentHashMap; /** * PojoConvertUtil * * @author littlehow * @time 2017-05-03 16:54 */ public class PojoConvertUtil { private static Logger logger = LoggerFactory.getLogger(PojoConvertUtil.class); /** * Variable cache */ private static final Map<String, Map> cacheFields = new ConcurrentHashMap(); private static final Set basicClass = new HashSet(); static { basicClass.add(Integer.class); basicClass.add(Character.class); basicClass.add(Byte.class); basicClass.add(Float.class); basicClass.add(Double.class); basicClass.add(Boolean.class); basicClass.add(Long.class); basicClass.add(Short.class); basicClass.add(String.class); basicClass.add(BigDecimal.class); } /** * Convert types with the same properties * @param orig * @param * @return */ public static T convertPojo(Object orig, Class targetClass) { try { T target = targetClass.newInstance(); /** Get all variables of the source object */ Field[] fields = orig.getClass().getDeclaredFields(); for (Field field : fields) { if (isStatic(field)) continue; /** Get target method */ Field targetField = getTargetField(targetClass, field.getName()); if (targetField == null) continue; Object value = getFiledValue(field, orig); if (value == null) continue; Class type1 = field.getType();…
Understanding of PO, VO, BO, POJO, DAO, DTO, TO, QO, Bean, conn in java
O/R Mapping is Object Relational Abbreviation for Mapping (object-relational mapping). In layman’s terms, it means binding objects to relational databases and using objects to represent relational data. in O/R In the world of Mapping, there are two basic and important things that need to be understood, namely VO and PO. VO, Value Object, PO, persistent object (Persisent Object), which are composed of a set of properties and their get and set methods. Structurally, there is nothing different about them. But it is completely different in its meaning and essence. 1. VO is created using the new keyword and recycled by GC. PO is created when new data is added to the database and deleted when data in the database is deleted. And it can only survive in one database connection and will be destroyed when the connection is disconnected. 2. VO is a value object. To be precise, it is a business object. It lives in the business layer and is used by business logic. The purpose of its existence is to provide a place for data to live. PO is stateful, and each attribute represents its current state. It is an object representation of physical data. Using it, we…
Concepts of PO, BO, VO, DTO, POJO, DAO in Java and their functions and project example diagram (translated)
PO (bean, entity, etc. naming): Persistant Object, the display status of records in the database table in the java object The most vivid understanding is that a PO is a record in the database. The advantage is that a record can be processed as an object and can be easily converted to other objects. BO (naming of service, manager, business, etc.): Business Object The main function is to encapsulate business logic as an object. This object can contain one or more other objects. Image is described as the form and action of an object. Of course, it also involves some forms and actions of other objects. For example, when dealing with a person’s business logic, there are behaviors such as sleeping, eating, working, going to work, etc. There are also behaviors that may lead to relationships with others. When dealing with business logic in this way, we can deal with BO. VO (from is also written this way): Value Object Mainly reflected in the object of the view, for a WEB The page encapsulates the properties of the entire page into an object. Then use a VO object to transmit and exchange between the control layer and the view layer.…
Bean conversion type_Conversion between DTO, VO, and PO in Java development should be done like this
Pain Points The emergence of a framework must solve a pain point, I think people often write about the following inconvenient operations. If the Car class is a database mapping class CarDTO is a DTO class Usually we will write a method like this to convert Even in the middle It also involves a lot of tedious operations such as type conversion and nesting, and all we want is to establish the mapping relationship between them. Is there a general mapping tool that can help us do all this? Of course there are, and there are quite a few. Some people say that Apache’s BeanUtil.copyProperties can achieve “but the performance is poor and prone to exceptions” and many standards strictly prohibit the use of this approach. Below is a comparison of several object mapping frameworks,MapStruct has the highest performance in most cases. Similar to lombok, Mapstruct is implemented at compile time, so there is generally no runtime performance problem. So let’s work on MapStruct today. Whether it is idea or eclipse, it is recommended to install the mapstruct plug-in. Installation Introduce maven dependency coordinates Write mapping…
Description of several objects in Java development (PO, VO, DTO, BO, POJO, DAO, SAO, etc.)
1. PO: (persistant object), persistent object can be seen as a java object that maps to a table in the database. Using Hibernate to generate PO is a good choice. 2. VO: (value object), value object is usually used for data transfer between business layers. Like PO, it only contains data. But it should be an abstracted business object, which may or may not correspond to a table, depending on the needs of the business. PO can only be used in the data layer, and VO is used in business logic layer and presentation layer. Each layer operates its own data objects, which reduces the coupling between layers and facilitates future system maintenance and expansion. 3. DAO: (Data Access Objects), data access object interfaceDAO is the Data Access Object data access interface, data access: as the name suggests Just deal with the database. Sandwiched between business logic and database resources. J2EE developers use the Data Access Object (DAO) design pattern to separate the underlying data access logic from the high-level business logic. Implementing the DAO pattern can focus more on writing data access code. The DAO pattern is one of the standard J2EE design patterns. Developers use this pattern to…
Concepts of PO, BO, VO, DTO, POJO, DAO in Java and their functions and project example diagram (translated)
PO (bean, entity, etc. naming): Persistant Object, the display status of records in the database table in the java object The most vivid understanding is that a PO is a record in the database. The advantage is that a record can be processed as an object and can be easily converted to other objects. BO (naming of service, manager, business, etc.): Business Object The main function is to encapsulate business logic as an object. This object can contain one or more other objects. Image is described as the form and action of an object. Of course, it also involves some forms and actions of other objects. For example, when dealing with a person’s business logic, there are behaviors such as sleeping, eating, working, going to work, etc. There are also behaviors that may lead to relationships with others. When dealing with business logic in this way, we can deal with BO. VO (from is also written this way): Value Object Mainly reflected in the object of the view, for a WEB The page encapsulates the properties of the entire page into an object. Then use a VO object to transmit and exchange between the control layer and the view layer.…
Bean conversion type_Conversion between DTO, VO, and PO in Java development should be done like this
Pain Points The emergence of a framework must solve a pain point, I think people often write about the following inconvenient operations. If the Car class is a database mapping class CarDTO is a DTO class Usually we write a method like this to convert Even in the middle It also involves a lot of tedious operations such as type conversion and nesting, and all we want is to establish the mapping relationship between them. Is there a general mapping tool that can help us do all this? Of course there are, and there are quite a few. Some people say that Apache’s BeanUtil.copyProperties can achieve “but the performance is poor and prone to exceptions” and many standards strictly prohibit the use of this approach. Below is a comparison of several object mapping frameworks,MapStruct has the highest performance in most cases. Similar to lombok, Mapstruct is implemented at compile time, so there is generally no runtime performance problem. So let’s work on MapStruct today. Whether it is idea or eclipse, it is recommended to install the mapstruct plug-in. Installation Introduce maven dependency coordinates Write mapping We…
JavaBean, POJO, Entity, VO, PO, DAO
Java Bean, POJO, Entity, and VO are actually Java objects, but they are used in different situations. Java Bean: It is an ordinary Java object, but with some constraints added. The declared property is private and implements the Get and set methods. POJO: Plain Old Java Object. Just an ordinary object; Entity: The meaning of entity. Entity is declared only when accessing the database. To put it bluntly, an Entity is a record in the corresponding table. When a record is inserted, an Entity is inserted. VO: Value Object. PO: Persistent Object. Persistent objects. There is nothing special about VO and PO, because with Hibernate, there will naturally be some new things. DAO: data Access Object: Data access object. Some directly translate it into database access objects. To put it simply, it means dealing with the database. According to the Spring MVC hierarchy: JavaBean: Presentation Layer Entity: Service layer Dao: Data access layer.
Java’s (PO, VO, TO, BO, DAO, POJO) explanation
Recently I am writing an interface for Android, in which the server data needs to define a VO (Value Object) object for encapsulation and transmission The concepts of VO, PO, BO, QO, DAO and POJO are still relatively vague, so I will record them here: O/R Mapping is the abbreviation of Object Relational Mapping. In layman’s terms, it means binding objects to relational databases and using objects to represent relational data. In the world of O/R Mapping, there are two basic and important things that need to be understood, namely VO and PO. PO (persistant object) persistent object The concept that appears when o/r is mapped. If there is no o/r Mapping, no such concept exists anymore. Usually corresponds to the data model (database ), which itself also handles some business logic. It can be seen as a java object that maps to a table in the database. The simplest PO corresponds to a record in a table in the database. Multiple records can use a collection of PO . PO should not contain any operations on the database. VO(value object) Value object Usually used for data transfer between business layers, and PO also only contains data. But it should…
The difference between POJO and JavaBeans, vo, po
POJO (Plain Ordinary Java Object) Simple Java objects, actually ordinary JavaBeans, Use POJO names to avoid and EJB It’s confusing, and the abbreviation is relatively straightforward. There are some classes with attributes and their getter setter methods, without business logic, which can sometimes be used as VO (value -object) or dto (Data Transform Object). Of course, if you have a simple operation attribute, it is also possible, but business methods are not allowed, and methods such as connection cannot be carried. POJO allows developers to focus on business logic and unit testing outside the framework. In addition, because POJO does not need to inherit the framework’s classes or implement its interfaces, developers can build inheritance structures and build applications with great flexibility. Because of its simplicity and flexibility, POJO can be expanded arbitrarily to suit multiple occasions, making it possible for a model to run through multiple layers. First write a core POJO, and then implement the business logic interface and persistence interface, which becomes the Domain Model; when the UI needs to be used, implement the data binding interface and become the VO (View Object). EJB (Enterprise JavaBean ) EJB is sun’s JavaEE server side Component Model , the…