Summary of the invention
The present invention provides a kind of method and apparatus that domain object is converted to view object, to solve automatically by field pair
The problem of image data model conversion is view object data model.
The method provided by the invention that domain object is converted into view object, comprising:
Attribute transitional information is created to domain object;
The domain object is converted into view object according to the attribute transitional information.
Further, method of the present invention, the attribute transitional information include: switch labels, objective attribute target attribute type and
Objective attribute target attribute title.
Further, method of the present invention, it is described to domain object create attribute transitional information the step of include:
The attribute of the domain object is added and is explained;Wherein, described explain includes the attribute transitional information.
Further, method of the present invention, it is described to be converted to the domain object according to the attribute transitional information
The step of view object includes:
Load includes the class file of the domain object;
The class file is inquired by Java Virtual Machine reflection mechanism;
If the note for inquiring the class file includes the switch labels, by the attribute root comprising the switch labels
Objective attribute target attribute is converted to according to the objective attribute target attribute type and target designation is added according to the objective attribute target attribute title.
Further, method of the present invention, the objective attribute target attribute type use the data type of JDK;
The described the step of domain object is converted to view object according to the attribute transitional information includes:
By calling the application programming interface of JDK to parse the attribute transitional information;
Call feed generator that the domain object is converted to the view according to the attribute transitional information after parsing
Figure object simultaneously generates source file.
The device provided by the invention that domain object is converted to view object, comprising:
Attribute transitional information module, for creating attribute transitional information to domain object;
Model conversion module, for the domain object to be converted to view object according to the attribute transitional information.
Further, device of the present invention, the attribute transitional information include: switch labels, objective attribute target attribute type and
Objective attribute target attribute title.
Further, device of the present invention, the attribute transitional information module are specifically used for:
The attribute of the domain object is added and is explained;Wherein, described explain includes the attribute transitional information.
Further, device of the present invention, the model conversion module are specifically used for:
Load includes the class file of the domain object;
The class file is inquired by Java Virtual Machine reflection mechanism;
If the note for inquiring the class file includes the switch labels, by the attribute root comprising the switch labels
Objective attribute target attribute is converted to according to the objective attribute target attribute type and target designation is added according to the objective attribute target attribute title.
Further, device of the present invention, the objective attribute target attribute type use the data type of JDK;
The model conversion module includes:
Parsing module, for by calling the application programming interface of JDK to parse the attribute transitional information;
Calling module, for calling feed generator according to the attribute transitional information after parsing by the domain object
It is converted to the view object and generates source file.
The present invention also provides a kind of storage medium, the storage medium stores computer program instructions, the computer journey
Sequence instructs method according to the present invention to be executed.
The present invention also provides a kind of calculating equipment, comprising: for storing the memory of computer program instructions and for holding
The processor of row computer program instructions, wherein when the computer program instructions are executed by the processor, trigger the calculating
Equipment executes method of the present invention.
The method and apparatus provided by the invention that domain object is converted into view object, using feed generator according to
Domain object data model (DO) is converted to view object data model (VO) automatically by attribute transitional information, is able to ascend conversion
Efficiency and speed reduce error probability, and the file generated also more standardizes, convenient for safeguarding.
Specific embodiment
Present invention is further described in detail with reference to the accompanying drawing.
Fig. 1 is the flow diagram of the method that domain object is converted to view object of the embodiment of the present invention one, such as Fig. 1
The method that domain object is converted to view object shown, that the embodiment of the present invention one provides, comprising:
Step S101 creates attribute transitional information to domain object.
The domain object is converted to view object according to the attribute transitional information by step S102.
Wherein, system bottom accesses database by database access object (DAO, Data Access Object)
(Database) data obtained are saved using domain object data model DO, then are reached upper-level system and passed through view in application
Figure object data model VO is presented to peripheral system.The field of the view object data model VO used when showing and actual use
Object data model DO may be inconsistent, it is therefore desirable to which domain object data model DO is converted to view object data model
VO。
When needing to convert, addition attribute transitional information is created to domain object data model DO.It is pre- according to actual needs
Feed generator is first set, and feed generator is the functional module that canned program is constituted, can be according to the objective attribute target attribute class received
Domain object data model DO is converted to view object data model VO by type and objective attribute target attribute title.
A method that domain object is converted to view object provided through the embodiment of the present invention, automatically by domain object
Data model (DO) is converted to view object data model (VO), is able to ascend transfer efficiency and speed, reduces error probability, and
And the file generated also more standardizes, it is convenient for safeguarding.
Fig. 2 is the flow diagram of the method that domain object is converted to view object of the embodiment of the present invention two, such as Fig. 2
It is shown, the method provided by Embodiment 2 of the present invention that domain object is converted into view object, comprising:
Step S201 adds the attribute of the domain object and explains.
Wherein, DAO class and used DO class that system generates are accessed for bottom data and are used.It is writing or is modifying
It is that each attribute of DO class adds annotating information when DO code.Described explain includes the attribute transitional information.The attribute turns
Changing information includes: switch labels, objective attribute target attribute type and objective attribute target attribute title.Switch labels can customize, to show the DO class
Attribute need to be converted to VO attribute.
Such as the addition of the attribute of Mr. Yu's DO class is explained, explaining includes attribute transitional information:
@D2V Integer agevvv*/private String age;
Wherein ,@D2V is switch labels, if passing through the reflection of Java Virtual Machine (JVM, Java Virtual Machine)
When mechanism inquires switch labels@D2V, illustrate that the attribute of the DO class needs to convert.Integer is objective attribute target attribute type, table
Show the type for needing that the attribute of the DO class is converted to VO attribute.Agevvv is objective attribute target attribute title, and objective attribute target attribute title can be certainly
Definition, i.e., after the attribute of the DO class being converted to VO attribute, the title of the VO class after the conversion.Wherein, the target category after conversion
Property type and objective attribute target attribute title can be consistent with the attribute type of the former DO class before conversion and Property Name.
Step S202, load include the class file of the domain object.
Wherein, after adding attribute transitional information by note mode to DO class, the DO class file is loaded.
Step S203 inquires the class file by Java Virtual Machine reflection mechanism.
Wherein, the DO class file that calling model converter passes through the reflection mechanism inquiry load of JVM.The reflection mechanism of java
It is that its attribute (Field) and method (Method) can be known for any one class (Class) in operating status, for
Any one object can call its method and attribute.The function of this dynamic acquisition information and dynamic call object method
It can be known as the reflection mechanism of java language, the dynamic row of program is even modified in the java program observation that it allows to be currently running
For.
Step S204 will be marked if the note for inquiring the class file includes the switch labels comprising the conversion
The attribute of label is converted to objective attribute target attribute according to the objective attribute target attribute type and adds target designation according to the objective attribute target attribute title.
Wherein, if model transformer inquires switch labels@D2V, illustrate that the attribute of the DO class needs to convert.Pass through tune
With application programming interface (API, Application Programming Interface), the note of DO class is solved
Analysis can call feed generator according to objective attribute target attribute to obtain objective attribute target attribute type Integer and objective attribute target attribute title agevvv
The attribute of domain object data model DO is converted to view object data by type Integer and objective attribute target attribute title agevvv
The name modifications of DO class are the title of VO class after conversion, generate source document after encapsulating by feed generator by the attribute of model VO
Part, for peripheral system use.
According to embodiments of the present invention two embodiment, the objective attribute target attribute type can use the data type of JDK.JDK
(Java Development Kit) is the Software Development Kit of Java language, is mainly used for mobile device, embedded device
On java application program.
In step S204, if the note for inquiring the class file includes the switch labels, by calling answering for JDK
The attribute transitional information is parsed with Program Interfaces, parsing obtains the objective attribute target attribute type in attribute transitional information, later,
Call feed generator that the domain object is converted to the view object simultaneously according to the attribute transitional information after parsing
Source file is generated, i.e. calling feed generator, the objective attribute target attribute type input file generator that parsing is obtained, feed generator
Attribute in DO class comprising the switch labels is converted to the attribute of target VO class according to objective attribute target attribute type, and according to described
Objective attribute target attribute title adds the title of target VO class, to obtain final source file.
Wherein, feed generator is the functional module that canned program is constituted, and writes completion in advance according to actual needs, can root
According to the objective attribute target attribute type and objective attribute target attribute title received, domain object data model DO is converted into view object data mould
Type VO.
Fig. 3 is the operation principle schematic diagram of the method that domain object is converted to view object of the embodiment of the present invention two,
As shown in figure 3, the working principle of the method that domain object is converted to view object of the embodiment of the present invention two is as follows:
1.DAO class can be used DO class from DB database access data.
2. explaining the DO class addition that DAO class uses to form DO data to be converted.Explaining includes attribute conversion letter
Breath :@D2V Integer agevvv*/private String age.Wherein ,@D2V is switch labels, and Integer is target
Attribute type, agevvv are objective attribute target attribute title
3. calling model converter, to load DO data to be converted.
4. model transformer inquires DO data to be converted by JVM reflection mechanism.If inquiring switch labels@D2V
When, note is parsed to obtain objective attribute target attribute type Integer and objective attribute target attribute title agevvv using the API of JDK.
5. calling feed generator according to objective attribute target attribute type Integer and objective attribute target attribute title agevvv by domain object
Data model DO is converted to view object data model VO.
6. the view object data model VO that feed generator by change data, that is, is converted to sends back model conversion
Device.
7. the view object data model VO being converted to is sent to peripheral system by model transformer.Model transformer
For the functional module that canned program is constituted, it is mainly used for implementing the method for the present invention.
Fig. 4 is the structural schematic diagram of the device that domain object is converted to view object of the embodiment of the present invention three, such as Fig. 4
Shown, the device that domain object is converted to view object of the embodiment of the present invention three includes: 41 He of attribute transitional information module
Model conversion module 42.
Attribute transitional information module 41, for creating attribute transitional information to domain object.
Model conversion module 42, for the domain object to be converted to view object according to the attribute transitional information.
In the embodiment of the present invention three, the attribute transitional information includes: switch labels, objective attribute target attribute type and target category
Property title.
In the embodiment of the present invention three, the attribute transitional information module 41 is specifically used for:
The attribute of the domain object is added and is explained;Wherein, described explain includes the attribute transitional information.
In the embodiment of the present invention three, the model conversion module 42 is specifically used for:
Load includes the class file of the domain object;
The class file is inquired by Java Virtual Machine reflection mechanism;
If the note for inquiring the class file includes the switch labels, by the attribute root comprising the switch labels
Objective attribute target attribute is converted to according to the objective attribute target attribute type and target designation is added according to the objective attribute target attribute title.
In the embodiment of the present invention three, the objective attribute target attribute type can use the data type of JDK.
The model conversion module 42 includes: parsing module 421 and calling module 422.
Parsing module 421, for by calling the application programming interface of JDK to parse the attribute transitional information;
Calling module 422, for calling feed generator according to the attribute transitional information after parsing by the field
Object is converted to the view object and generates source file.
Device described in the embodiment of the present invention three is the realization device of method described in the embodiment of the present invention two, specific former
Reason is identical as method described in the embodiment of the present invention two, and details are not described herein again.
In an embodiment of the invention, a kind of calculating equipment is also provided, comprising: for storing computer program instructions
Memory and processor for executing computer program instructions, wherein when the computer program instructions are executed by the processor
When, trigger the method for calculating equipment and executing the embodiment of the present invention.
In the present invention one typical configuration, calculating equipment includes one or more processors (CPU), input/defeated
Outgoing interface, network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or
The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium
Example.
In an embodiment of the invention, a kind of storage medium is also provided, the storage medium storage computer program refers to
It enables, the computer program instructions are executed according to the method for the embodiment of the present invention.
Computer readable storage medium includes permanent and non-permanent, removable and non-removable media, can be by appointing
What method or technique realizes that information stores.Information can be computer readable instructions, data structure, program device or other
Data.The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory
(SRAM), dynamic random access memory (DRAM), other kinds of random access memory (RAM), read-only memory
(ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory techniques, CD-ROM (CD-
ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storages
Equipment or any other non-transmission medium, can be used for storage can be accessed by a computing device information.
It should be noted that the present invention can be carried out in the assembly of software and/or software and hardware, for example, can adopt
With specific integrated circuit (ASIC), general purpose computer or any other realized similar to hardware device.In some embodiments
In, software program of the invention can be executed by processor to realize above step or function.Similarly, software of the invention
Program (including relevant data structure) can be stored in computer readable recording medium, for example, RAM memory, magnetic or
CD-ROM driver or floppy disc and similar devices.In addition, some of the steps or functions of the present invention may be implemented in hardware, for example,
As the circuit cooperated with processor thereby executing each step or function.
It is obvious to a person skilled in the art that invention is not limited to the details of the above exemplary embodiments, Er Qie
In the case where without departing substantially from spirit or essential attributes of the invention, the present invention can be realized in other specific forms.Therefore, no matter
From the point of view of which point, the present embodiments are to be considered as illustrative and not restrictive, and the scope of the present invention is by appended power
Benefit requires rather than above description limits, it is intended that all by what is fallen within the meaning and scope of the equivalent elements of the claims
Variation is included in the present invention.Any reference signs in the claims should not be construed as limiting the involved claims.This
Outside, it is clear that one word of " comprising " does not exclude other units or steps, and odd number is not excluded for plural number.That states in device claim is multiple
Unit or device can also be implemented through software or hardware by a unit or device.The first, the second equal words are used to table
Show title, and does not indicate any particular order.