CN106933554A - Class conversion method and device - Google Patents
Class conversion method and device Download PDFInfo
- Publication number
- CN106933554A CN106933554A CN201511023820.3A CN201511023820A CN106933554A CN 106933554 A CN106933554 A CN 106933554A CN 201511023820 A CN201511023820 A CN 201511023820A CN 106933554 A CN106933554 A CN 106933554A
- Authority
- CN
- China
- Prior art keywords
- class
- mapper
- source
- conversion
- target
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
This application discloses a species conversion method and device.Wherein, the method includes:Acquisition source class object and class pair as, wherein, source class object is the object of source class, and class pair is as the object for target class;The mapping relations of acquisition source class object and class pair as between;And the conversion of source class object and class pair as between is performed according to mapping relations and mapper by class converter, wherein, class conversion method is encapsulated in class converter in advance, class transformation rule is encapsulated in mapper in advance, class conversion method is used to perform the conversion between class according to class transformation rule.Present application addresses the complex technical problem of conversion operation between two classes in correlation technique.
Description
Technical field
The application is related to computer realm, in particular to a species conversion method and device.
Background technology
During actual development, it is often necessary to do the conversion between two classes, the two classes generally fall into different field,
For example, database and application program are belonging respectively to, or belong to different systems etc..The characteristics of the two classes is non-
Often similar, for example, most of field is similar with Property Name, only fraction field and attribute are inconsistent, and carry out
Special conversion logic is needed during conversion.
For above-mentioned situation, the conversion between typically all carrying out two classes manually in code, respectively by an object
Each property value is assigned to the corresponding property value of another object.Generally, in addition it is also necessary to perform reverse turn between two classes
Change, reverse conversion code and forward conversion code very class Sihe are repeated, and simply assignment direction changes.If two
Individual class adds new attribute, it is necessary to add conversion code simultaneously in forward conversion and reverse conversion, also quite similar.
So code cannot also be multiplexed, if two other class needs also exist for conversion, in addition it is also necessary to which similar code is write in repetition.
For the complex problem of conversion operation between two classes in correlation technique, effective solution is not yet proposed at present
Scheme.
The content of the invention
The main purpose of the application is to provide a species conversion method and device, with solve in correlation technique two classes it
Between the complex problem of conversion operation.
To achieve these goals, according to the one side of the application, there is provided a species conversion method.The method bag
Include:Acquisition source class object and class pair as, wherein, source class object is the object of source class, and class pair is as being target
The object of class;The mapping relations of acquisition source class object and class pair as between;And by class converter according to mapping
Relation and mapper perform the conversion of source class object and class pair as between, wherein, encapsulated in advance in class converter
Class conversion method, encapsulates class transformation rule in advance in mapper, class conversion method is used to be performed according to class transformation rule
Conversion between class.
Further, mapper includes member mapper and class mapper, wherein, member mapper includes source member's name
Claim and target members' title, class mapper includes source class, target class and member mapper set, wherein, member's mapping
The type of each element is the type of member mapper in device set.
Further, source class object and class pair are performed as between according to mapping relations and mapper by class converter
Conversion include:Traversal member mapper's set, according to the source member of each member mapper in member mapper's set
The value of name acquiring each source member;And will be each according to target members' title of mapping relations and each member mapper
The value of individual source member is accordingly assigned to the target members of each member mapper.
Further, source class object and class pair are performed as between according to mapping relations and mapper by class converter
Conversion include:Traversal member mapper's set, according to the source member of each member mapper in member mapper's set
The value of name acquiring each source member;Judge that each member mapper whether there is member's conversion method respectively;For sentencing
Break and to exist the member mapper of member's conversion method, call member's conversion method to the value of the source member of member mapper
Perform conversion, the value of the source member after being changed, and by the value of the source member after conversion be assigned to corresponding target into
Member;And for judging the member mapper in the absence of member's conversion method, directly by the source member of member mapper
Value be assigned to corresponding target members.
Further, mapper also includes set member's mapper, and set member's mapper includes source neutron member type
With target neutron member type, set member's mapper inherits member mapper, by class converter according to mapping relations
And mapper performs the conversion of source class object and class pair as between and includes:Traversal member mapper's set, and respectively
Each member mapper performs following operation in gathering member mapper:Source member's title according to member mapper is obtained
Take the value of source member;Judge whether member mapper is set member's mapper;Judging that member mapper is not collection
When closing member mapper, the target members' title according to mapping relations and member mapper accordingly assigns the value of source member
It is worth to the target members of member mapper;When it is set member's mapper to judge member mapper, source member is traveled through
Value in each source member's subitem value, and created according to each target neutron member type in set member's mapper respectively
Build each target members' subitem;And the value of each source member's subitem is accordingly assigned to each target members' subitem.
Further, class mapper is also packaged with class mapper inverting method in advance, wherein, class mapper inverting method
Reversion for performing class mapper, the class mapper after reversion is used for the conversion of performance objective class to source class, by class
Converter performs the conversion of source class object and class pair as between according to mapping relations and mapper to be included:Class is called to reflect
Emitter inverting method, the class mapper after being inverted;And after class converter is according to mapping relations and reversion
Class mapper is by class pair as being converted to source class object.
To achieve these goals, according to the another aspect of the application, there is provided a species conversion equipment.The device bag
Include:First acquisition unit, for obtain source class object and class pair as, wherein, source class object for source class object,
Class pair is as the object for target class;Second acquisition unit, for obtaining source class object and class pair as between
Mapping relations;And converting unit, for by class converter according to mapping relations and mapper perform source class object and
Conversion of the class pair as between, wherein, class conversion method is encapsulated in advance in class converter, sealed in advance in mapper
Class transformation rule is filled, class conversion method is used to perform the conversion between class according to class transformation rule.
Further, mapper includes member mapper and class mapper, wherein, member mapper includes source member's name
Claim and target members' title, class mapper includes source class, target class and member mapper set, wherein, member's mapping
The type of each element is the type of member mapper in device set.
Further, converting unit includes:Acquisition module, for traveling through member mapper's set, maps according to member
The value of each source member of source member's name acquiring of each member mapper in device set;And assignment module, for root
According to mapping relations and each member mapper target members' title by the value of each source member be accordingly assigned to each into
The target members of member's mapper.
Further, class mapper is also packaged with class mapper inverting method in advance, wherein, class mapper inverting method
Reversion for performing class mapper, the class mapper after reversion is used for the conversion of performance objective class to source class, and conversion is single
Unit includes:Calling module, for calling class mapper inverting method, the class mapper after being inverted;And conversion
Module, for by class converter according to mapping relations and reversion after class mapper by class pair as being converted to source class
Object.
The application by obtain source class object and class pair as, wherein, source class object for source class object, target class
Object is the object of target class;The mapping relations of acquisition source class object and class pair as between;And changed by class
Device performs the conversion of source class object and class pair as between according to mapping relations and mapper, wherein, in class converter
Class conversion method is encapsulated in advance, class transformation rule is encapsulated in mapper in advance, class conversion method is used to be turned according to class
Change rule perform class between conversion, solve the problems, such as that conversion operation is complex between two classes in correlation technique,
And then reached the effect for quickly and easily realizing being changed between two classes.
Brief description of the drawings
The accompanying drawing for constituting the part of the application is used for providing further understanding of the present application, the schematic reality of the application
Apply example and its illustrate for explaining the application, do not constitute the improper restriction to the application.In the accompanying drawings:
Fig. 1 is the flow chart of the class conversion method according to the embodiment of the present application;And
Fig. 2 is the schematic diagram of the class conversion equipment according to the embodiment of the present application.
Specific embodiment
It should be noted that in the case where not conflicting, the feature in embodiment and embodiment in the application can phase
Mutually combination.Describe the application in detail below with reference to the accompanying drawings and in conjunction with the embodiments.
In order that those skilled in the art more fully understand application scheme, below in conjunction with the embodiment of the present application
Accompanying drawing, is clearly and completely described to the technical scheme in the embodiment of the present application, it is clear that described embodiment
The only embodiment of the application part, rather than whole embodiments.Based on the embodiment in the application, ability
The every other embodiment that domain those of ordinary skill is obtained under the premise of creative work is not made, should all belong to
The scope of the application protection.
It should be noted that term " first ", " in the description and claims of this application and above-mentioned accompanying drawing
Two " it is etc. for distinguishing similar object, without for describing specific order or precedence.It should be appreciated that this
The data that sample is used can be exchanged in the appropriate case, so as to embodiments herein described herein.Additionally, term
" comprising " and " having " and their any deformation, it is intended that covering is non-exclusive to be included, for example, comprising
The process of series of steps or unit, method, system, product or equipment are not necessarily limited to those steps clearly listed
Rapid or unit, but may include not listing clearly or intrinsic for these processes, method, product or equipment
Other steps or unit.
For the ease of description, some terms and concept being related to the application below are illustrated:
Class:Be object-oriented program development language in a kind of complicated data type, be by different types of data and
Aggregate that the operation related to these data is packaged together, wherein, class is the abstract of object, and pair as if class
Instantiation.
According to the embodiment of the present application, there is provided a species conversion method.Fig. 1 is changed according to the class of the embodiment of the present application
The flow chart of method, as shown in figure 1, the method includes steps S102 to step S106:
Step S102, obtain source class object and class pair as, wherein, source class object is the object of source class, target class
Object is the object of target class.
It should be noted that the source class and target class of the embodiment of the present application can arbitrarily be belonged to different field and exist big
Part field two classes similar with attribute, for example, source class is the class in Java development languages, target class is opened for C++
Class in hair language.Source class object and class pair need to perform two objects of class changed as being respectively, for example,
Source class object is class Person in Java development languages, including ID (identifier), Name (name), Age (years
Age) three members, class pair as being class Person in C++ development languages, including identifier PID (identifier),
PName (name), three members of PAge (age).
Step S104, obtains the mapping relations of source class object and class pair as between.
For example, source class object be Java development languages in class Person, including ID (identifier), Name (name),
Three members of Age (age), class pair is as being class Person in C++ development languages, including identifier PID (marks
Know symbol), PName (name), three members of PAge (age), in order to realize source class object to class pair as
Conversion, then need to obtain the mapping relations of source class object and class pair elephant, i.e. member id and member PID couples in advance
Should, member Name corresponding with member PName and member Age and member Page it is corresponding, such that it is able to by source class
The value of object each member is accordingly assigned to each member of class pair elephant.
Step S106, source class object and class pair are performed as between by class converter according to mapping relations and mapper
Conversion, wherein, encapsulate class conversion method in advance in class converter, encapsulate class transformation rule in advance in mapper,
Class conversion method is used to perform the conversion between class according to class transformation rule.
The embodiment of the present application by obtain source class object and class pair as, wherein, source class object for source class object,
Class pair is as the object for target class;The mapping relations of acquisition source class object and class pair as between;And pass through
Class converter performs the conversion of source class object and class pair as between according to mapping relations and mapper, wherein, class turns
Class conversion method is encapsulated in advance in parallel operation, class transformation rule is encapsulated in mapper in advance, class conversion method is used for root
According to class transformation rule perform class between conversion, the embodiment of the present application by class converter can be automatically obtained two classes it
Between conversion, solve the problems, such as that conversion operation is complex between two classes in correlation technique, and then reached convenience
Rapidly realize the effect changed between two classes.
Alternatively, the mapper of the embodiment of the present application includes member mapper and class mapper, wherein, member mapper
Including source member's title and target members' title, class mapper includes source class, target class and member mapper set, its
In, the type of each element is the type of member mapper in member mapper's set.
The mapper of the embodiment of the present application can be the class for pre-defining, pre-defined in member mapper source into
The member member such as title and target members' title, has pre-defined source class, target class and member mapper in class mapper
The members such as set.It should be noted that the member mapper's set in class mapper refers to the set of multiple elements
(for example, array), the type of each element is the type of member mapper in set.For example, the member of definition is reflected
Emitter is as follows:
Class Member{
Public:
String SourName;
String DestName;
};
From the foregoing, it will be observed that member mapper Member, i.e. class Member, including SourName and DestName two
Individual member, then member mapper gathers can be:Member Mem [N], wherein, each yuan in array Mem [N]
The type of element is Member.
Alternatively, source class object and class pair are performed as between according to mapping relations and mapper by class converter
Conversion includes:Traversal member mapper's set, according to source member's name of each member mapper in member mapper's set
Claim the value of each source member of acquisition;And according to target members' title of mapping relations and each member mapper by each
The value of source member is accordingly assigned to the target members of each member mapper.
In the embodiment of the present application, each member mapper in traversal member mapper set, and reflected according to each member
The value of the name acquiring of source member each source member in emitter, for example, according to ID in above-mentioned source class object class Person,
Tri- member Names of Name, Age obtain tri- values of member of ID, Name, Age, such that it is able to according to source class pair
As and mapping relations of the class pair as between the value of member id is assigned to member PID respectively, by member Name's
Value is assigned to member PName and the value of member Age is assigned into member Page, realizes source class object to target class
The conversion of object.
Preferably, for the ease of the conversion between different pieces of information, held according to mapping relations and mapper by class converter
The conversion of row source class object and class pair as between includes:Traversal member mapper's set, collects according to member mapper
The value of each source member of source member's name acquiring of each member mapper in conjunction;Judging each member mapper respectively is
It is no to there is member's conversion method;For the member mapper for judging to have member's conversion method, member conversion side is called
Method performs conversion to the value of the source member of member mapper, the value of the source member after being changed, and by the source after conversion
The value of member is assigned to corresponding target members;And for judging the member mapper in the absence of member's conversion method,
The value of the source member of member mapper is directly assigned to corresponding target members.
Member's conversion method of the embodiment of the present application can be configured according to the actual requirements, specifically, member conversion side
Method can be the method for data type conversion, for example, Boolean is converted into character string, or according to pre-
If the method that rule carries out data conversion, for example, the value of source member is performed into Hash operation.
In the embodiment of the present application, traversal member mapper set, according to each member mapping in member mapper's set
The value of source member's name acquiring of device each source member, and the member mapper is judged with the presence or absence of member's conversion method,
When the member mapper has member's conversion method, member's conversion method of the member mapper is called to reflect the member
The value of the source member of emitter performs conversion, the value of the source member after being changed, and the value of the source member after conversion is assigned
It is worth to corresponding target members;Judge the member mapper do not exist member's conversion method when, then can directly by
The value of the source member of the member mapper is copied to corresponding target members.
Preferably, mapper also include set member's mapper, set member's mapper include source neutron member type and
Target neutron member type, set member's mapper inherits member mapper, by class converter according to mapping relations and
Mapper performs the conversion of source class object and class pair as between to be included:Traversal member mapper's set, and it is right respectively
Each member mapper performs following operation in member mapper's set:Source member's name acquiring according to member mapper
The value of source member;Judge whether member mapper is set member's mapper;Judging that member mapper is not set
During member mapper, target members' title according to mapping relations and member mapper is by the value of source member accordingly assignment
To the target members of member mapper;When it is set member's mapper to judge member mapper, traversal source member's
The value of each source member's subitem in value, and created according to each target neutron member type in set member's mapper respectively
Each target members' subitem;And the value of each source member's subitem is accordingly assigned to each target members' subitem.
In actual conditions, can also there is set in some classes, there is the conversion of the class of set for the ease of those, this
Apply embodiment mapper also include set member's mapper, set member's mapper include source neutron member type and
Target neutron member type, set member's mapper inherits member mapper.
In the embodiment of the present application, each member mapper in traversal member mapper set, and respectively to member's mapping
Each member mapper performs following steps S11 to step S15 in device set:
Step S11, the value of the source member name acquiring source member according to member mapper.
Step S12, judges whether member mapper is set member's mapper.
For example, judging whether source member is set in the member mapper, i.e., whether source member wraps in the member mapper
Containing many sub- members, if source member includes many sub- members in the member mapper, that is, the member mapper is judged
It is set member's mapper, otherwise the member mapper is not set member's mapper.
Step S13, when it is not set member's mapper to judge member mapper, reflects according to mapping relations and member
The value of source member is accordingly assigned to target members' title of emitter the target members of member mapper.
The embodiment of the present application when it is not set member's mapper to judge member mapper, directly by the value pair of source member
It is assigned to target members with answering.
Step S14, when it is set member's mapper to judge member mapper, travels through each source in the value of source member
The value of member's subitem, and respectively according to each target neutron member type in set member's mapper create each target into
Member's subitem.
Step S15, each target members' subitem is accordingly assigned to by the value of each source member's subitem.
Specifically, value, target members subitem, set member mapping of the embodiment of the present application according to each source member's subitem
Device, sub- member's class mapper call class converter, perform the conversion between set member mapper neutron member.
Preferably, for the ease of realizing the reverse conversion of class, class mapper is also packaged with class mapper inverting method in advance,
Wherein, class mapper inverting method is used to perform the reversion of class mapper, and the class mapper after reversion is used for performance objective
Class performs source class object and class pair as it by class converter to the conversion of source class according to mapping relations and mapper
Between conversion include:Class mapper inverting method is called, the class mapper after being inverted;And by class converter
According to the class mapper after mapping relations and reversion by class pair as being converted to source class object.
Alternatively, the class mapper inverting method of the embodiment of the present application can as follows S21 to step S23 realities
The reversion of existing class mapper:
Step S21, the class mapper target class before reversion is set to by the class mapper source class after reversion, and target class sets
It is set to source class.
Step S22, each member mapper in traversal member mapper's set, and member mapper's inverting method is called,
Member mapper after generation reversion, in member mapper's set of the class mapper being added to after reversion.
Wherein, member mapper's inverting method can realize member mapper by S221 to step S222 as follows
Reversion:
Step S221, by the member mapper's source member's title after reversion be set to reversion before member mapper's target into
Member's title, target members' title is set to source member's title.
Step S222, member mapper of the miscellaneous part value from before reversion is copied directly to the member mapper after reversion.
Step S23, class mapper of the miscellaneous part value from before reversion is copied directly to the class mapper after reversion.
In the embodiment of the present application, after realizing the reversion of class mapper by calling class mapper inverting method, by mesh
As source class object, source class object is as class pair as and the class mapper after reversion calls class for mark class object
Converter realizes class pair as the conversion to source class object.
The class conversion method of the embodiment of the present application is illustrated with an example below.Specifically, implement in the application
In example, following mapper and class converter are pre-defined:
1. class mapper is defined:
Define whether to be switched comprising attribute;
Define whether to be switched comprising field;
Define whether to be switched comprising non-shared member;
Definition source class;
Define target class;
Define member mapper's set;
Class mapper inverting method is defined, the class mapper after reversion is returned.
Alternatively, such mapper inverting method realizes the process of the reversion of class mapper with above-mentioned steps S21 to step
S23, will not be repeated here.
2. member mapper is defined:
Define source member's title;
Define target members' title;
Define member's conversion method;
Define member mapper's inverting method.
Alternatively, member mapper's inverting method realizes the process of the reversion of member mapper with above-mentioned steps S221
To step S222, will not be repeated here.
3. definition set member mapper, the mapper is inherited from member mapper, i.e., all comprising member mapper
Member, and also additional members can be defined:
Define sub- member's class mapper;
Define source neutron member type;
Define target neutron member type;
Definition set member mapper's inverting method.
Wherein, set member's mapper inverting method can realize that member is reflected by S31 to step S33 as follows
The reversion of emitter:
Step S31, calls member mapper's inverting method, and the member mapper after being inverted is converted into collection
Close member mapper.
Step S32, is set to the source neutron member type in the set member's mapper after reversion former set member and reflects
Target neutron member type in emitter.
Step S33, former set member is set to by the target neutron member type in the set member's mapper after reversion
Source neutron member type in mapper.
4. class converter is defined:
Forward conversion method is defined, i.e., is changed from source class to target class, the parameter of the forward conversion method is source class object,
Class pair as with class mapper, specifically, forward conversion method be achieved by the steps of source class to target class change:
Step S41, builds and obtains member's switch.
Step S42, traversal member mapper's set, and each member mapper in member mapper's set is performed such as
Lower step S43.
Step S43, source member's title and acquisition member's switch according to member mapper, obtains source member's information, such as
Fruit is obtained less than source member's information, is directly skipped;If having got source member's information, according to information about firms and source
Class object obtains the value of the source member.
Source member's information of the embodiment of the present application can be the metadata of source member.Specifically, if getting source member
Information, then obtain the value of the source member according to source member's information and source class object;If not getting source member's information,
Then directly skip.
Step S44, if member's conversion method defined in member mapper, using member's conversion method is reflected member
The value of the source member of emitter is changed, the value of the source member after being changed.
Specifically, member's conversion method of the embodiment of the present application can be configured according to the actual requirements, specifically, into
Member's conversion method can be the method for data type conversion, for example, Boolean is converted into character string, it is also possible to
It is the method that data conversion is carried out according to preset rules, for example, the value of source member is performed into Hash operation.
Step S45, judges whether member mapper is set member's mapper.
Specifically, if it is judged that member mapper is not set member's mapper, then step S46 is performed, if sentenced
Breaking, member mapper be set member's mapper, then perform step S47.
Step S46, target members' title and acquisition member's switch according to member mapper, obtains target members' information,
If obtain fall short information about firms, directly skip, if getting target members' information, according to target into
Member's information and class pair are as setting the value of target members using the value of the source member after the value of source member or conversion.
Target members' information of the embodiment of the present application can also be the metadata of target members.
Step S47, target members' title and acquisition member's switch according to member mapper, obtains target members' information,
Directly skipped if fall short information about firms is obtained, if getting target members' information, believed using target members
Breath and target class object acquisition target members value.It should be noted that now the value of the value of source member and target members is all
It is set.Specifically, the value for source member being performed as follows is assigned to target members:
Step S471, travels through the value of each source member's subitem in the value of source member, respectively according in set member's mapper
Each target neutron member type creates each target members' subitem.
Step S472, according to the value of subitem, target members' subitem, set member's mapper, sub- member's class in source member
Mapper calls forward conversion method, performs the conversion between set member mapper neutron member.
The class converter of the embodiment of the present application has also pre-defined reverse conversion method, i.e., changed from target class to source class,
The parameter of the reverse conversion method is source class object, destination object class and class mapper.Specifically, the embodiment of the present application
Reverse conversion method call class mapper inverting method, the class mapper after being inverted;Then by class pair
As source class object, source class object is as class pair as and the class mapper after reversion calls forward conversion
Method realizes class pair as the conversion to source class object.
After the definition of above-mentioned mapper and class converter is completed, the embodiment of the present application can be utilized and defined
Mapper and class converter realize the conversion of source class object and class pair elephant, specifically, the class of the embodiment of the present application
Conversion method comprises the following steps:
Step S202:By source class object and class pair as being assigned to above-mentioned class converter respectively.
Step S204:The mapping relations of acquisition source class object and class pair as between.
Specifically, the mapping relations of source class object and class pair as between can be pre-defined by user.
Step S206:Source class object and class pair turning as between are realized by the class converter of the embodiment of the present application
Change.
As can be seen from the above description, the embodiment of the present application need not manually perform the conversion between class, it is only necessary to
Define the mapping relations between source class and target class, you can the conversion between two classes is performed automatically, compared to existing
Conversion between carrying out two classes manually in the code in technology, operates more convenient and in hgher efficiency.Additionally, this
Apply for forward conversion and reverse conversion that the class conversion method of embodiment can be conveniently carried out between two classes, without
What is repeated writes similar codes;And the class conversion method of the embodiment of the present application has certain versatility, can be used in
Conversion between two different classes, for example, class Person in class Person and C++ development language in Java development languages
Between conversion, class User in class User and C++ development language in Java development languages.
It should be noted that can be in such as one group computer executable instructions the step of the flow of accompanying drawing is illustrated
Performed in computer system, and, although logical order is shown in flow charts, but in some cases, can
Shown or described step is performed with different from order herein.
According to the another aspect of the embodiment of the present application, there is provided a species conversion equipment, such conversion equipment can be used for
The class conversion method of the embodiment of the present application is performed, the class conversion method of the embodiment of the present application can also be implemented by the application
The class conversion equipment of example is performed.
Fig. 2 is the schematic diagram of the class conversion equipment according to the embodiment of the present application, as shown in Fig. 2 the device includes:The
One acquiring unit 10, second acquisition unit 20 and converting unit 30.
First acquisition unit 10, for obtain source class object and class pair as, wherein, source class object is right for source class
As class pair is as the object for target class.
Second acquisition unit 20, for obtaining the mapping relations of source class object and class pair as between.
Converting unit 30, for performing source class object and class pair according to mapping relations and mapper by class converter
Conversion as between, wherein, class conversion method is encapsulated in advance in class converter, class is encapsulated in mapper in advance and is turned
Rule is changed, class conversion method is used to perform the conversion between class according to class transformation rule.
The embodiment of the present application by first acquisition unit 10 obtain source class object and class pair as, wherein, source class object
It is the object of source class, class pair is as the object for target class;Second acquisition unit 20 obtains source class object and target class
Mapping relations between object;And converting unit 30 performs source class by class converter according to mapping relations and mapper
The conversion of object and class pair as between, wherein, class conversion method is encapsulated in advance in class converter, in mapper
Class transformation rule is encapsulated in advance, and class conversion method is used to, according to the conversion between class transformation rule execution class, solve
The complex problem of conversion operation between two classes in correlation technique, and then reached and quickly and easily realize two classes
Between change effect.
Alternatively, mapper includes member mapper and class mapper, wherein, member mapper includes source member's title
With target members' title, class mapper include source class, target class and member mapper set, wherein, member mapper
The type of each element is the type of member mapper in set.
Alternatively, converting unit includes:Acquisition module, for traveling through member mapper's set, according to member mapper
The value of each source member of source member's name acquiring of each member mapper in set;And assignment module, for basis
The value of each source member is accordingly assigned to each member by target members' title of mapping relations and each member mapper
The target members of mapper.
Preferably, class mapper is also packaged with class mapper inverting method in advance, wherein, class mapper inverting method is used
In the reversion for performing class mapper, the class mapper after reversion is used for the conversion of performance objective class to source class, converting unit
Including:Calling module, for calling class mapper inverting method, the class mapper after being inverted;And modulus of conversion
Block, for by class converter according to mapping relations and reversion after class mapper by class pair as being converted to source class pair
As.
The class conversion equipment includes processor and memory, above-mentioned first acquisition unit, second acquisition unit and conversion
Unit etc. is stored in memory as program unit, by computing device storage said procedure list in memory
Unit realizes corresponding function.
Kernel is included in processor, is gone in memory to transfer corresponding program unit by kernel.Kernel can set one
Or more, the conversion between two classes is performed by adjusting kernel parameter.
Memory potentially includes the volatile memory in computer-readable medium, random access memory (RAM) and/
Or the form, such as read-only storage (ROM) or flash memory (flash RAM) such as Nonvolatile memory, memory includes at least one
Individual storage chip.
Present invention also provides a kind of computer program product, when being performed on data processing equipment, it is adapted for carrying out just
The program code of beginningization there are as below methods step:Acquisition source class object and class pair as, wherein, source class object is source
The object of class, class pair is as the object for target class;The mapping relations of acquisition source class object and class pair as between;
And the conversion of source class object and class pair as between is performed according to mapping relations and mapper by class converter, its
In, class conversion method is encapsulated in advance in class converter, encapsulate class transformation rule, class conversion side in advance in mapper
Method is used to perform the conversion between class according to class transformation rule.
Above-mentioned the embodiment of the present application sequence number is for illustration only, and the quality of embodiment is not represented.
In above-described embodiment of the application, the description to each embodiment all emphasizes particularly on different fields, and does not have in certain embodiment
The part of detailed description, may refer to the associated description of other embodiment.
In several embodiments provided herein, it should be understood that disclosed technology contents, can be by other
Mode realize.Wherein, device embodiment described above is only schematical, such as division of described unit,
Can be a kind of division of logic function, there can be other dividing mode when actually realizing, for example multiple units or component
Can combine or be desirably integrated into another system, or some features can be ignored, or do not perform.It is another, institute
Display or the coupling each other for discussing or direct-coupling or communication connection can be by some interfaces, unit or mould
The INDIRECT COUPLING of block or communication connection, can be electrical or other forms.
The unit that is illustrated as separating component can be or may not be it is physically separate, it is aobvious as unit
The part for showing can be or may not be physical location, you can with positioned at a place, or can also be distributed to
On multiple units.Some or all of unit therein can be according to the actual needs selected to realize this embodiment scheme
Purpose.
In addition, during each functional unit in the application each embodiment can be integrated in a processing unit, it is also possible to
It is that unit is individually physically present, it is also possible to which two or more units are integrated in a unit.It is above-mentioned integrated
Unit can both be realized in the form of hardware, it would however also be possible to employ the form of SFU software functional unit is realized.
If the integrated unit is to realize in the form of SFU software functional unit and as independent production marketing or use
When, can store in a computer read/write memory medium.Based on such understanding, the technical scheme of the application
The part for substantially being contributed to prior art in other words or all or part of the technical scheme can be produced with software
The form of product is embodied, and the computer software product is stored in a storage medium, including some instructions are used to make
Obtain a computer equipment (can be personal computer, server or network equipment etc.) and perform each implementation of the application
The all or part of step of example methods described.And foregoing storage medium includes:USB flash disk, read-only storage (ROM,
Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk,
Magnetic disc or CD etc. are various can be with the medium of store program codes.
The above is only the preferred embodiment of the application, it is noted that for the ordinary skill people of the art
For member, on the premise of the application principle is not departed from, some improvements and modifications can also be made, these improve and moisten
Decorations also should be regarded as the protection domain of the application.
Claims (10)
1. a species conversion method, it is characterised in that including:
Acquisition source class object and class pair as, wherein, the source class object is the object of source class, the target
Class object is the object of target class;
Obtain the mapping relations of the source class object and the class pair as between;And
The source class object and the class pair are performed according to the mapping relations and mapper by class converter
Conversion as between, wherein, class conversion method is encapsulated in advance in the class converter, it is pre- in the mapper
Class transformation rule is first encapsulated, the class conversion method is used for according to turning between class transformation rule execution class
Change.
2. method according to claim 1, it is characterised in that the mapper includes that member mapper and class map
Device, wherein, the member mapper includes source member's title and target members' title, and the class mapper includes
The source class, the target class and member mapper set, wherein, each yuan in member mapper's set
The type of element is the type of the member mapper.
3. method according to claim 2, it is characterised in that by the way that class converter is according to the mapping relations and reflects
Emitter performs the conversion of the source class object and the class pair as between to be included:
Member mapper's set is traveled through, according to the source of each member mapper in member mapper set
Member Name obtains the value of each source member;And
Each source member described in target members' title general according to the mapping relations and each member mapper
Value be accordingly assigned to the target members of each member mapper.
4. method according to claim 2, it is characterised in that by the way that class converter is according to the mapping relations and reflects
Emitter performs the conversion of the source class object and the class pair as between to be included:
Member mapper's set is traveled through, according to the source of each member mapper in member mapper set
Member Name obtains the value of each source member;
Judge that described each member mapper whether there is member's conversion method respectively;
For the member mapper for judging to have member's conversion method, member's conversion method pair is called
The value of the source member of the member mapper performs conversion, the value of the source member after being changed, and by after conversion
The value of source member be assigned to corresponding target members;And
For judging the member mapper in the absence of member's conversion method, directly by the member mapper
The value of source member be assigned to corresponding target members.
5. method according to claim 2, it is characterised in that the mapper also includes set member's mapper,
Set member's mapper includes source neutron member type and target neutron member type, and the set member is reflected
Emitter inherits the member mapper, and the source is performed according to the mapping relations and mapper by class converter
The conversion of class object and the class pair as between includes:
Member mapper's set is traveled through, and respectively to each member mapper in member mapper set
Perform following operation:
The value of the source member name acquiring source member according to the member mapper;
Judge whether the member mapper is set member's mapper;
When it is not set member's mapper to judge the member mapper, according to the mapping relations and
The value of the source member is accordingly assigned to the member mapper by target members' title of the member mapper
Target members;
When it is set member's mapper to judge the member mapper, in the value of the traversal source member
The value of each source member's subitem, and respectively according to each target neutron member type in set member's mapper
Create each target members' subitem;And
The value of each source member's subitem is accordingly assigned to described each target members' subitem.
6. method according to claim 2, it is characterised in that the class mapper is also packaged with class mapper in advance
Inverting method, wherein, the class mapper inverting method is used to perform the reversion of the class mapper, after reversion
Class mapper be used to perform the conversion of the target class to the source class, by class converter according to the mapping
Relation and mapper perform the conversion of the source class object and the class pair as between to be included:
The class mapper inverting method is called, the class mapper after being inverted;And
By the class converter according to the class mapper after the mapping relations and the reversion by the target class
Object is converted to the source class object.
7. a species conversion equipment, it is characterised in that including:
First acquisition unit, for obtain source class object and class pair as, wherein, the source class object be source
The object of class, the class pair is as the object for target class;
Second acquisition unit, for obtaining the mapping relations of the source class object and the class pair as between;
And
Converting unit, for performing the source class object according to the mapping relations and mapper by class converter
And conversion of the class pair as between, wherein, class conversion method is encapsulated in advance in the class converter,
Class transformation rule is encapsulated in the mapper in advance, the class conversion method is used for according to the class transformation rule
Perform the conversion between class.
8. device according to claim 7, it is characterised in that the mapper includes that member mapper and class map
Device, wherein, the member mapper includes source member's title and target members' title, and the class mapper includes
The source class, the target class and member mapper set, wherein, each yuan in member mapper's set
The type of element is the type of the member mapper.
9. device according to claim 8, it is characterised in that the converting unit includes:
Acquisition module, for traveling through member mapper set, according in member mapper set each
The value of source member's name acquiring of member mapper each source member;And
Assignment module, for being incited somebody to action according to target members' title of the mapping relations and each member mapper
The value of each source member is accordingly assigned to the target members of each member mapper.
10. device according to claim 8, it is characterised in that the class mapper is also packaged with class mapper in advance
Inverting method, wherein, the class mapper inverting method is used to perform the reversion of the class mapper, after reversion
Class mapper be used to perform the conversion of the target class to the source class, the converting unit includes:
Calling module, for calling the class mapper inverting method, the class mapper after being inverted;And
Modular converter, for being mapped according to the class after the mapping relations and the reversion by the class converter
Device is by the class pair as being converted to the source class object.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201511023820.3A CN106933554A (en) | 2015-12-30 | 2015-12-30 | Class conversion method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201511023820.3A CN106933554A (en) | 2015-12-30 | 2015-12-30 | Class conversion method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN106933554A true CN106933554A (en) | 2017-07-07 |
Family
ID=59441839
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201511023820.3A Pending CN106933554A (en) | 2015-12-30 | 2015-12-30 | Class conversion method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106933554A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109901822A (en) * | 2019-01-08 | 2019-06-18 | 平安科技(深圳)有限公司 | The mutual shifting method of object, device and storage medium, server |
CN109947418A (en) * | 2019-03-27 | 2019-06-28 | 厦门纳龙科技有限公司 | A kind of data model translation method and device |
CN112148299A (en) * | 2020-09-16 | 2020-12-29 | 上海中通吉网络技术有限公司 | Byte code object copying method, device, equipment and storage medium |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1570862A (en) * | 2003-04-25 | 2005-01-26 | 微软公司 | Runtime polymorphism |
CN1786925A (en) * | 2005-03-08 | 2006-06-14 | 中国科学院软件研究所 | TTCN-3 testing system basedon C++ mapping and its testing method |
US20080168430A1 (en) * | 2007-01-10 | 2008-07-10 | Bea Systems, Inc. | Open controls |
CN102830975A (en) * | 2012-08-15 | 2012-12-19 | 深圳市翌日科技有限公司 | Method and device for code conversion from assembly language to high-level language |
CN103605543A (en) * | 2013-11-19 | 2014-02-26 | 北京国双科技有限公司 | Validation attribute converting method and validation attribute converting device |
CN104731911A (en) * | 2015-03-24 | 2015-06-24 | 浪潮集团有限公司 | Dynamic mapping and converting method for data table and entity class |
-
2015
- 2015-12-30 CN CN201511023820.3A patent/CN106933554A/en active Pending
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1570862A (en) * | 2003-04-25 | 2005-01-26 | 微软公司 | Runtime polymorphism |
CN1786925A (en) * | 2005-03-08 | 2006-06-14 | 中国科学院软件研究所 | TTCN-3 testing system basedon C++ mapping and its testing method |
US20080168430A1 (en) * | 2007-01-10 | 2008-07-10 | Bea Systems, Inc. | Open controls |
CN102830975A (en) * | 2012-08-15 | 2012-12-19 | 深圳市翌日科技有限公司 | Method and device for code conversion from assembly language to high-level language |
CN103605543A (en) * | 2013-11-19 | 2014-02-26 | 北京国双科技有限公司 | Validation attribute converting method and validation attribute converting device |
CN104731911A (en) * | 2015-03-24 | 2015-06-24 | 浪潮集团有限公司 | Dynamic mapping and converting method for data table and entity class |
Non-Patent Citations (1)
Title |
---|
WEIXIN_30588827: "AutoMapper(一)——实现数据契约和实体类之间的转换", 《HTTPS://BLOG.CSDN.NET/WEIXIN_30588827/ARTICLE/DETAILS/99776677》 * |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109901822A (en) * | 2019-01-08 | 2019-06-18 | 平安科技(深圳)有限公司 | The mutual shifting method of object, device and storage medium, server |
CN109901822B (en) * | 2019-01-08 | 2022-08-12 | 平安科技(深圳)有限公司 | Object conversion method and device, storage medium and server |
CN109947418A (en) * | 2019-03-27 | 2019-06-28 | 厦门纳龙科技有限公司 | A kind of data model translation method and device |
CN112148299A (en) * | 2020-09-16 | 2020-12-29 | 上海中通吉网络技术有限公司 | Byte code object copying method, device, equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109508420B (en) | Method and device for cleaning attributes of knowledge graph | |
CN107402955A (en) | The method and apparatus for determining the index grid of geography fence | |
CN106886570A (en) | page processing method and device | |
CN107918666A (en) | Method of data synchronization and system on a kind of block chain | |
CN107656729A (en) | Updating device, method and the computer-readable recording medium of List View | |
CN103412757A (en) | Realizing method of personalized integrated framework of mobile applications | |
CN103314371A (en) | Retrieval method and system | |
CN104281441B (en) | Data extraction method and device based on MVC | |
CN108170638A (en) | Computational methods, device, equipment and storage medium based on Excel tables | |
CN106933554A (en) | Class conversion method and device | |
CN107632827A (en) | The generation method and device of the installation kit of application | |
CN107885501A (en) | Obtain the method and device of the mutual adduction relationship of component in Android | |
CN113094355A (en) | Model instantiation method, device, equipment and medium based on domestic communication protocol | |
CN109145235A (en) | Method, apparatus and electronic equipment for analyzing web page | |
CN106873952A (en) | The data handling system and method and application apparatus of mobile terminal webpage development | |
CN109976755A (en) | Language is the method and electronic equipment of Vue making of cartoon effect based on programming | |
CN109032590A (en) | A kind of configuration method, device, terminal and the storage medium of visual development environment | |
CN109543708A (en) | Merge the mode identification method towards diagram data of topological characteristic | |
CN106570714A (en) | Method and apparatus for recommending matching object picture, and method and apparatus for establishing mapping relation | |
CN106649347A (en) | Interest information identification method and apparatus | |
US6842888B2 (en) | Method and apparatus for hierarchically restructuring portions of a hierarchical database based on selected attributes | |
CN109657125A (en) | Data processing method, device, equipment and storage medium based on web crawlers | |
CN108984339A (en) | Data reconstruction method and Related product | |
CN107220251A (en) | Generate the method and device of description information | |
CN107766036A (en) | A kind of construction method of module, construction device and terminal device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB02 | Change of applicant information | ||
CB02 | Change of applicant information |
Address after: 100083 No. 401, 4th Floor, Haitai Building, 229 North Fourth Ring Road, Haidian District, Beijing Applicant after: Beijing Guoshuang Technology Co.,Ltd. Address before: 100086 Cuigong Hotel, 76 Zhichun Road, Shuangyushu District, Haidian District, Beijing Applicant before: Beijing Guoshuang Technology Co.,Ltd. |
|
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20170707 |