CN109542418A - Service code generating method and terminal - Google Patents

Service code generating method and terminal Download PDF

Info

Publication number
CN109542418A
CN109542418A CN201811385948.8A CN201811385948A CN109542418A CN 109542418 A CN109542418 A CN 109542418A CN 201811385948 A CN201811385948 A CN 201811385948A CN 109542418 A CN109542418 A CN 109542418A
Authority
CN
China
Prior art keywords
java
code
bean object
information
field
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.)
Granted
Application number
CN201811385948.8A
Other languages
Chinese (zh)
Other versions
CN109542418B (en
Inventor
彭敏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
BEIJING QIANDING INTERNET TECHNOLOGY Co Ltd
Original Assignee
BEIJING QIANDING INTERNET TECHNOLOGY Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by BEIJING QIANDING INTERNET TECHNOLOGY Co Ltd filed Critical BEIJING QIANDING INTERNET TECHNOLOGY Co Ltd
Priority to CN201811385948.8A priority Critical patent/CN109542418B/en
Publication of CN109542418A publication Critical patent/CN109542418A/en
Application granted granted Critical
Publication of CN109542418B publication Critical patent/CN109542418B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms

Abstract

The invention discloses a kind of Service code generating method and terminals, this method comprises: obtaining the field information of each field in the summary info and table of table in database, and convert summary info and field information to the entity information of Java specification;Whether the Java code of preordering method is stored with where judging Service layers in Java Development Framework;If being stored with the Java code of preordering method where Service layers in Java Development Framework, corresponding Service code is generated according to the method name of the Java code of preordering method, the variable of Bean object and Bean object.Technical solution of the present invention, according to table summary info and the field information of each field, it is converted to the entity information for the Java specification that is corresponding to it, and Service class is generated according to entity information and often uses code, the repeated work that development efficiency avoids developer from writing same code in each project is improved, the uniformity of developer's working efficiency and code is improved.

Description

Service code generating method and terminal
Technical field
The present invention relates to Java development technique fields, in particular to a kind of Service code generating method and calculating Machine terminal.
Background technique
With the rapid development of IT (Internet Technology, Internet technology) industry, the work of developer is got over Come it is more important, write code occupy developer's overwhelming majority time.
In existing computer programming language, representative of the Java language as static Object-Oriented Programming Language is fabulous Ground realizes object-oriented theory, allows programmer to carry out complicated programming with the graceful mode of thinking, use scope is increasingly Extensively.
In existing Java Development Framework, represent layer, Business Logic and data access layer are generally included, if one Mybatis plug-in unit has been arrived in use in project, when developer operates a table, both needs to write SQL code, compile again Java code is write, in the three-decker of Java Development Framework, needs to write Service interface, Service realizes that class, Dao connect Mouth, Dao realize multiple classes and the method such as class and POJO Java Bean.If there is 10 tables in the database of a project, that According to the three-decker of Java Development Framework, need to write at least 50 classes, there are also different methods in each class, another In a project, the multiple classes for writing identical function and method are also needed, causes developer in different projects, repeats to compile The code for writing said function causes developer's working efficiency low;And not due to the coding style of different developers Together, lead to that the same project development comes out code is lack of standardization, disunity, increase the probability of code compilation failure.
Summary of the invention
In view of the above problems, the embodiment of the present invention is designed to provide a kind of Service code generating method and calculating Machine terminal, so as to solve the deficiencies in the prior art.
According to embodiment of the present invention, a kind of Service code generating method is provided, is applied to Java and develops frame Frame, this method comprises:
Obtain the field information of each field in the summary info and the table of table in database, and by the summary info and The field information is converted into the entity information of Java specification, wherein the entity information includes variable and the institute of Bean object State the method name of Bean object;
Whether the Java code of preordering method is stored with where judging Service layers in Java Development Framework;
If the Java code is stored in Java Development Framework where described Service layers, according to the Java generation The method name of code, the variable of the Bean object and the Bean object generates corresponding Service code.
It is described " to convert the summary info and the field information in above-mentioned Service code generating method Java specification entity information " include:
The summary info is parsed, and summary parsing information is converted into the Bean object of Java specification;
The field information is parsed, and field parsing information is converted to the variable of the Bean object, then The method name of the Bean object is generated according to the variable of the Bean object.
It is described " according to the Java code of the preordering method, described in above-mentioned Service code generating method The method name of the variable of Bean object and the Bean object generates corresponding Service code " include:
Corresponding Service code is created according to the type of the variable of Bean object and the method name of the Bean object Frame;
In the frame of the Service code, preordering method described in the call by variable for the Bean object Java code.
In above-mentioned Service code generating method, the preordering method is get method, getList method, the side add Method, addSelective method, delete method or update method.
In above-mentioned Service code generating method, the summary info of the table includes the title of table and the remarks of table Information;
Described " summary info is parsed, and summary parsing information is converted into the Bean object of Java specification " Include:
It is segmented according to title of the preset rules to the table, each section is converted into the Bean title of predetermined format, And the Bean object for standardizing all sections of Bean name combination at Java;
Where the remark information to be written to the Bean object in the form of java class remarks in the file of class.
In above-mentioned Service code generating method, the field information of each field includes the name of each field in the table Claim;
Described " field information is parsed, and field parsing information is converted to the variable of the Bean object, Then the method name of the Bean object is generated according to the variable of the Bean object " include:
The field name is segmented according to preset rules, is by all sections of content transformation of the title of the field The name variable of the Bean object of Java specification;
The method name of the Bean object is generated according to the functional circuit information of the name variable and the preordering method Claim.
In above-mentioned Service code generating method, further includes:
Interface class and realization class of the table at Service layers is respectively created according to the Bean object of the table;
The Service code is separately added into described Service layers of interface class and realization class.
In above-mentioned Service code generating method, the preset rules include:
It is segmentation with the underscore in each field name in the title or table of the table if include underscore Point, each field name is segmented in the title or table to the table;
If in the title or table of the table in each field name include upper and lower case letter, by each capitalization and All lowercases after the mother of the capitalization are divided into one section.
According to another implementation of the invention, a kind of code generating unit is provided, which includes:
Module is obtained, for obtaining the field information of each field in the summary info of table and the table in database, and will The summary info and the field information are converted into the entity information of Java specification, wherein the entity information includes Bean The method name of the variable of object and the Bean object;
Judgment module, for whether being stored with the Java of preordering method in Java Development Framework where judging Service layers Code;
Generation module, if being stored with the Java code, shown generation in Java Development Framework where described Service layers Module is used to be generated according to the method name of the Java code, the variable of the Bean object and the Bean object corresponding Service code.
Another embodiment according to the present invention, provides a kind of terminal, and the terminal includes storage Device and processor, the memory run the computer program so that institute for storing computer program, the processor It states terminal and executes above-mentioned Service code generating method.
Yet another embodiment according to the present invention provides a kind of computer readable storage medium, is stored with above-mentioned The computer program used in terminal.
The technical scheme provided by this disclosed embodiment may include it is following the utility model has the advantages that
A kind of Service code generating method and terminal in the present invention, by the summary info of table in database and The field information of each field is converted into the entity information of Java specification in table, automatic according to entity information and quickly generate predetermined party The Service code of method avoids developer from writing the repeated work of same code in each project, improves exploit person employee Make efficiency;The skimble-scamble problem of code as caused by developer's coding style difference is avoided, the rule of Service code are improved Plasticity and uniformity improve the success rate of Service code compilation.
To enable the above objects, features and advantages of the present invention to be clearer and more comprehensible, preferred embodiment is cited below particularly, and cooperate Appended attached drawing, is described in detail below.
Detailed description of the invention
In order to illustrate more clearly of technical solution of the present invention, letter will be made to attached drawing needed in the embodiment below It singly introduces, it should be understood that the following drawings illustrates only certain embodiments of the present invention, therefore is not construed as to the present invention The restriction of protection scope for those of ordinary skill in the art without creative efforts, can be with root Other relevant attached drawings are obtained according to these attached drawings.
Fig. 1 shows the structural schematic diagram of a kind of Java Development Framework provided in an embodiment of the present invention and database interaction.
Fig. 2 shows a kind of flow diagrams of Service code generating method provided in an embodiment of the present invention.
Fig. 3 shows the flow diagram of another kind Service code generating method provided in an embodiment of the present invention.
Fig. 4 shows a kind of flow diagram of code generating method provided in an embodiment of the present invention.
Fig. 5 shows a kind of flow diagram of data grabber recognition methods provided in an embodiment of the present invention.
Fig. 6 shows the flow diagram of another data grabber recognition methods provided in an embodiment of the present invention.
Fig. 7 shows a kind of process being segmented by preset rules to title provided in an embodiment of the present invention and illustrates Figure.
Fig. 8 shows a kind of flow diagram of Dao code generating method provided in an embodiment of the present invention.
Fig. 9 shows the flow diagram of another kind Dao code generating method provided in an embodiment of the present invention.
Figure 10 shows a kind of flow diagram of Mybatis code generating method provided in an embodiment of the present invention.
Figure 11 shows the flow diagram of another kind Mybatis code generating method provided in an embodiment of the present invention.
Figure 12 shows a kind of structural schematic diagram of Service code generating unit provided in an embodiment of the present invention.
Main element symbol description:
10-Java Development Framework;11- represent layer;12- Business Logic;13- data access layer;14-Mybatis SQL Layer;15- database;
100-Service code generating unit;110- obtains module;120- judgment module;130- generation module.
Specific embodiment
Below in conjunction with attached drawing in the embodiment of the present invention, technical solution in the embodiment of the present invention carries out clear, complete Ground description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.Usually exist The component of the embodiment of the present invention described and illustrated in attached drawing can be arranged and be designed with a variety of different configurations herein.Cause This, is not intended to limit claimed invention to the detailed description of the embodiment of the present invention provided in the accompanying drawings below Range, but it is merely representative of selected embodiment of the invention.Based on the embodiment of the present invention, those skilled in the art are not doing Every other embodiment obtained under the premise of creative work out, shall fall within the protection scope of the present invention.
Embodiment 1
As shown in Figure 1, for a kind of structural representation of Java Development Framework and database interaction provided in an embodiment of the present invention Figure.The Java Development Framework 10 is divided for represent layer 11, Business Logic 12, data access layer 13 and Mybatis SQL layer.
Shown represent layer 11 is commonly used to handle and control request of data and page jump etc..
For the Business Logic 12 for generating Service code, the Service code includes business interface class (example Such as IXX Service class, wherein XX can be the title of different business) and business service class (such as XX Service class, wherein XX can be the title of different business).It may include get function, getList in the business interface class and the business service class Function, add function, addSelective function, update function, updateSelective function, delete function and GetCount function etc..
Wherein, the get function is used to obtain the entity information of table in database, for example, the remarks of the title of table, table are believed Title, the type of each field, the remarks of each field and the primary key relationships of each field etc. of each field in breath, table.
GetList function is used to obtain the entity information list of table in database.
Add function is for adding entity information in table into the database.
AddSelective function is used for judging whether the entity information is empty, if in fact according to entity information to be added Body information is that sky is then added, if entity information is empty without addition.
Entity information of the update function for table in more new database.
Entity information of the updateSelective function for table in selective updating database.
Delete function is used to delete the entity information of table in database.
Sum of the getCount function for entity information in table in statistical data.
For Business Logic 12 when receiving the request of the transmission of represent layer 11, calling the Service code of generation to execute should Request corresponding operation.
The data access layer 13 for generating Dao code, the Dao code include service interface class (such as XXIDao.java class, wherein XX can be the title of different entities information) and service implementing type (such as XXDaoImp1.java Class, wherein XX can be the title of different entities information).It may include get in the service interface class and the service implementing type Function, add function and update function etc..
Dao (Data access object, data access object) is an OODB Object Oriented Data Base interface, the number According to access layer 13 when receiving the request that the Business Logic 12 is sent, the realization of Dao code and the database of generation are called Between connection, to execute the corresponding operation of the request.
Mybatis SQL layer 14 includes get function, add letter in the Mybatis code for generating Mybatis code Several and update function etc..
Mybatis SQL layer 14 supports common SQL query, storing process and advanced mapping, according to data access layer 13 The request of transmission calls directly the Mybatis code of generation, can call directly session control information in the Mybatis code (Session) SQL statement in is handled database 15 to execute the corresponding operation of the request.
The database 15 is used for the entity information of storage table.The database 15 can be relevant database, such as MySQL database, Oracal database etc..
As shown in Fig. 2, a kind of flow diagram of the Service code generating method proposed for the embodiment of the present invention.
The Service code generating method includes the following steps:
In step S410, the field information of each field in the summary info and table of table in database is obtained, and by summary Information and field information are converted into the entity information of Java specification.
In the step s 420, whether there is the Java generation of preordering method in the Java Development Framework where judging Service layers Code.
Specifically, described Service layers is the Business Logic 12 for generating Service code.
In Java development platform, it will usually some common functions be put into a file, such as library function, library letter The function that number is stored in function library.Library function has specific function, entry call parameter and return value.Using the library letter When number, the function directly can be called directly by entry call parameter, and return to a result (i.e. return value).
The Java code that the preordering method whether is previously stored in Java Development Framework is judged, if Java Development Framework In be previously stored with the Java code of the preordering method, advance to step S430;If not deposited in advance in Java Development Framework The Java code for storing up the preordering method advances to step S440.
Wherein, the preordering method may include get series methods (get function, getList function), add (add function, AddSelective function) series methods, delete method and update method etc..
In step S430, is generated and corresponded to according to the method name of Java code, the variable of Bean object and Bean object Service code.
Specifically, described " raw according to the method name of Java code, the variable of the Bean object and the Bean object At corresponding Service code " include:
Corresponding Service generation is created according to the type of the variable of the Bean object and the method name of the Bean object The method of code;In the method, the Java code of preordering method described in the call by variable for the Bean object.
In step S440, empty information is returned.
If the Java code of the preordering method is not stored in advance in Java Development Framework, the preordering method is executed Service code automatically generates.
As shown in figure 3, be the flow diagram of another kind Service code generating method provided in an embodiment of the present invention, The Service code generating method includes the following steps:
In step S510, the field information of each field in the summary info and table of table in database is obtained, and by summary Information and field information are converted into the entity information of Java specification.
In step S520, interface class and realization class of the table at Service layers are respectively created according to the Bean object of table.
Specifically, Service layers (generating the Business Logic 12 of Service code) are the effects formed a connecting link, to It is upper to provide the realization of method of servicing for represent layer 11, institute is provided downwards for Dao layers (generating the data access layer 13 of Dao code) State the connection between data access layer 13 and represent layer 11.
In the Business Logic 12 for generating Service code, and it is divided into service interface layer and Service realization layer, is servicing Interface layer includes interface class, includes realizing class in Service realization layer.It may each comprise the Java generation of all preordering methods in every one kind Code.
In step S530, whether there is the Java generation of preordering method in the Java Development Framework where judging Service layers Code.
The Java code that the preordering method whether is previously stored in Java Development Framework is judged, if Java Development Framework In be previously stored with the Java code of the preordering method, advance to step S540;If not deposited in advance in Java Development Framework The Java code for storing up the preordering method advances to step S550.
Wherein, the preordering method may include get series methods (get function, getList function), add (add function, AddSelective function) series methods, delete method and update method etc..
In step S540, corresponded to according to the type of the variable of Bean object and the creation of the method name of Bean object The frame of Service code.
Specifically, using the type of variable in Bean object as the type of this method, according to the variable pair in Bean object The frame of the method for the corresponding Java code of method name creation party's legitimate name answered.
For example, Integer getA ()
{ method content }
Wherein, Integer is the type of variables A in Bean object, and getA is the title for the get function of variables A, side Method content is the specific code of the get method, can be stored in advance in Java Development Framework, the specific generation of the get method Code can be called directly when in use by entry call parameter, and the type of the entry call parameter is similarly Integer type, returns Returning value is Integer type.
In step S550, empty information is returned.
In step S560, in the frame of Service code, for the call by variable preordering method of Bean object Java code is to generate the corresponding Service code of the preordering method.
Specifically, it in the content part of the frame of Service code, using the variable of Bean object as parameter, calls predetermined The Java code of method obtains the preordering method for the predetermined registration operation of the variable of Bean object.
For example, Integer getA (String S)
{ String Str=get (A);
return Str;}
Wherein, the Service code of the above-mentioned getA method for having automatically generated an Integer type, in code, definition For one character type variable Str as return value, the value of the Str is the knot after the variables A execution get operation for Bean object Fruit.
In step S570, in Service layers of interface classes and realize that be separately added into the preordering method corresponding in class Service code.
Specifically, it in interface class and realizes and is separately added into the corresponding Service code of the preordering method in class, so that should Service code executes the operation of corresponding preordering method.
Fig. 4 shows a kind of flow diagram of code generating method provided in an embodiment of the present invention.The code building side Method is applied in Java Development Framework.
The Service code generating method includes the following steps:
In step S1100, the field information of each field in the summary info and table of table in database is obtained, and by summary Information and field information are converted into the entity information of Java specification.
Further, as shown in figure 5, described " obtain the field letter of each field in the summary info and table of table in database Breath converts summary info and field information to the entity information of Java specification " include:
In step s 110, the field information of each field in the summary info and table of table in database is obtained.
Specifically, the field information of each field in the summary info and table of table in data is obtained by JDBC.
Specifically, the JDBC (connection of Java DataBase Connectivity, java database) is that one kind is used for The Java API for executing SQL statement can provide unified access interface by JDBC for a variety of relational databases, pass through the interface Obtain the field information of each field in the summary info and table of table in data.
In the step s 120, summary info is parsed, and summary parsing information is converted into the Bean of Java specification Object.
Specifically, the summary info of the table includes the title of table and the remark information of table.By the summary info of the table It is segmented, each section of content is converted respectively, and the conversion results of all sections of content are combined into Java rule The Bean object of model provides unified, specification Bean object with the operation for subsequent code building.
In step s 130, field information is parsed, and field parsing information is converted to the variable of Bean object, Then the method name of Bean object is generated, according to the variable of Bean object to carry out the automatic life of the code of the preordering method At.
Specifically, the field information includes field name, field type, field remark information and field primary key relationships Deng.
Field name is segmented, each section of content is converted respectively, and by the conversion of all sections of content As a result it is combined into the name variable of the Bean object of Java specification;The field type is converted into the class of Java specification Type;The title of the preordering method of Java specification is generated according to the title of the name variable of Bean object and preordering method.
Further, the preordering method includes set method and get method.
Further, as shown in fig. 6, described " obtain the field letter of each field in the summary info and table of table in database Breath converts summary info and field information to the entity information of Java specification " further include:
In step S210, SQL query statement is called by JDBC, the summary of table in database is obtained according to query result The field information of each field in information and table.
Specifically, SQL query statement is called to inquire the entity information of table in database by JDBC technology, than Such as, the word of SQL query statement each field of the summary info to the table of database and table respectively is called in Java API code Segment information is inquired, and obtains the result of SQL query statement inquiry.
For example, the SQL query statement includes:
SELECT Name from sysobjects where xtype='u'and status >=0 inquiry table name Claim
All words in SELECT Name from syscolumns where id=object_id (' table name ') inquiry table Section, etc..
It in step S220, is segmented according to title of the preset rules to table, is converted into predetermined format for each section Bean title, and the Bean object that all sections of Bean name combination is standardized at Java.
Further, as shown in fig. 7, the preset rules include:
In step s310, the title of each field in the title or table of table is obtained.
Specifically, in programming language, the title of the title of the table or the field usually can by letter, number or Underscore composition, such as my_name, MyName etc..
In step s 320, judge whether there is underscore or capitalization in the title.
Specifically, if specified requirements A is the feelings for having underscore in the title or table of the table in the title of each field Condition, condition B are to have the case where capitalization in the title of each field in the title or table of the table.
If at least condition A is set up, including two kinds of situations: when only condition A establishment or condition A, condition B are set up, advancing To step S330;If condition A, condition B are invalid, step S360 is advanced to;If only condition B is set up, step is advanced to S340。
In step S330, it is marked as cut-point below, the title of each field is divided in the title or table to table Section.
It specifically, include underscore or the table in the title of each field in the title of the table perhaps table When in title or table in the title of each field simultaneously including underscore and capitalization, it is marked as cut-point below, to institute Title is stated to be segmented.
For example, if in the title or table of table each field entitled a_b_c, be marked as cut-point below, can be by a_ B_c points are tri- sections of a, b, c;If the entitled a_bBe_cD of each field, is marked as cut-point below in the title or table of table, A_bBe_cD can be divided is tri- sections of a, bBe, cD.
In step S340, all lowercases after each capitalization and the capitalization are divided into one group.
Specifically, do not include underscore in the title of each field in the title of the table or table, include capital letter When female, using capitalization position as cut-point, all lowercases after capitalization and the capitalization are divided It is one group.
For example, if in the title or table of table each field entitled AacDef, with capitalization position be point Cutpoint, can be divided to AacDef is two sections of Aac, Def;If the entitled AacDEf of each field in the title or table of table, with big Female position write as cut-point, can divide AacDEf is tri- sections of Aac, D, Ef.
In step S350, it is converted into predetermined format type by each section, and all sections of content is combined into Java rule The Bean object of model or the variable of Bean object.
Further, the predetermined format can also be able to be hump formula for all the elements are converted into capitalization Format write, wherein the hump formula format write is divided into small hump formula format and big hump formula format.
For example, if in the title or table of table each field entitled a_b_c, cut-point is marked as below, by a_b_c It is divided into tri- sections of a, b, c, in Java language, the ASCII character value of a, b, c can be subtracted 32, it is corresponding big obtains the lowercase Write it is female be converted into ASCII character value, the content of the uppercase format after obtaining tri- sections of A, B, C conversions, and by this three sections capitalization lattice Content A, B, the C in combination of formula are the Bean object of Java specification or the variables A BC of Bean object.
For another example, if in the title of table or table each field entitled AacDef, with capitalization position be point Cutpoint, can be divided to AacDef is two sections of Aac, Def, two sections of contents of Aac, Def can be separately converted to small hump formula format AacDef or big hump formula format AacDef.
In step S360, it converts title to the Bean object of Java specification or the variable of Bean object.
If the title of the table does not include underscore, and when not including capitalization, can be by the title transformation in planta The Bean object standardized for the Java of above-mentioned predetermined format
If the title of each field does not include underscore in the table, and when not including capitalization, can be by the name Transformation in planta is referred to as the variable of the Bean object of the Java specification of above-mentioned predetermined format.
In step S230, the file of class where the remark information of table to be written to Bean object in the form of java class remarks In.
Specifically, addition is annotated with the readability for being conducive to improve code in code, for example, can be infused according to code in Java Comment section where Bean object is written in the remark information by the format released in the file of class.
For example, the format of addition uniline annotation: // remark information;The format of addition multirow annotation :/* remark information */.
In step S240, the title of field each in table is segmented according to preset rules, by the title of the field All sections of content transformations be predetermined format Bean object name variable.
In step s 250, the type of field each in table is converted into corresponding Java regulating style.
Wherein, the type may include integer, character type, floating type etc..
Specifically, it before the entity information automatic code generating according to table in database, also needs the entity information of table Change into unified standard Java specification entity information, in order to be subsequently generated Service code, Dao code and It is directly called when Mybatis code.
For example, if in table each field type be CHAR, VARCHAR, TINY TEXT, TEXT, MEDIUM TEXT, The character types such as LONGTEXT, TINY BLOG, BLOG, MEDIUM BLOG, LONG BLOG can be converted to the character type Java String type in Java development platform;
If the type of each field is BIT, BOOL, TINY INT, SMALL INT, MEDIUM INT, INT, BIG in table The integer can be converted to the Java Integer type in Java development platform by the integers such as INT;
If the type of each field is the floating types such as FLOAT, DOUBLE, DECIMAL in table, the floating type can be converted to Java Double type in Java development platform;
If the type of each field is the Data Dates types such as DATA in table, the Data Date type can be converted to Java Java Date type in development platform.
In step S260, name variable is converted into the title of preordering method according to the first preset rules, according to change The title of amount title, Java regulating style and preordering method automatically generates the code of preordering method.
Further, first preset rules include:
The functional circuit information that the preordering method is added before the title of the variable, by the function of the preordering method It can the title of description information and the variable as the preordering method.
Specifically, by the name format of the preordering method is defined as: the functional circuit information+Bean object of preordering method Variable title.
For example, if preordering method is get method, for each variable of Bean object, setting preordering method can be unified Entitled getA, getB etc., wherein A, B etc. are the variable in Bean object.
In step S1200, according to the method name of the Java code of preordering method, the variable of Bean object and Bean object Claim to generate corresponding Service code.
In step S1300, according to the method name of the SQL code of preordering method, the variable of Bean object and Bean object Claim to generate corresponding Dao code.
Further, as shown in figure 8, it is described " according to the SQL code of preordering method, the variable of the Bean object and institute The method name for stating Bean object generates corresponding Dao code " include:
In step S610, the field information of each field in the summary info and table of table in database is obtained, and by summary Information and summary info are converted into the entity information of Java specification.
In step S620, the current session control information of database is obtained.
Specifically, all of the current SQLSession (SQL session control information) of database are obtained by JDBC technology Content.
In step S630, the operation for whether having preordering method in session control information is judged.
If there is the record of the operation of preordering method in the session control information, step S640 is advanced to;If the session There is no the record of the operation of preordering method in control information, advances to step S650.
In step S640, according to the method name of the SQL code of preordering method, the variable of Bean object and Bean object Generate corresponding Dao code.
Specifically, described " according to the method name of the SQL code of preordering method, the variable of Bean object and Bean object Generate corresponding Dao code " include:
Corresponding Dao code is created according to the type of the variable of the Bean object and the method name of the Bean object Method;In the method, the SQL code of preordering method described in the call by variable for the Bean object.
In step S640, empty information is returned.
Further, as shown in figure 9, it is described " according to the SQL code of preordering method, the variable of the Bean object and institute The method name for stating Bean object generates corresponding Dao code " include:
In step S710, the field information of each field in the summary info and table of table in database is obtained, and by summary Information and summary info are converted into the entity information of Java specification.
In step S720, interface class and realization class of the table at Dao layers are respectively created according to the Bean object of table.
Specifically, Dao layers (generating the data access layer 13 of Dao code) are articulamentums, are upwards generation Service generation The Business Logic 12 of code provides the realization of method of servicing, provides Service layers downwards for Mybatis SQL layer 14 and (generates The Business Logic 12 of Service code) and Mybatis SQL layer 14 between connection.
In the data access layer 13 for generating Dao code, and it is divided into service interface layer and Service realization layer, in service interface Layer includes interface class, includes realizing class in Service realization layer.It may each comprise the Java code of all preordering methods in every one kind.
In step S730, the current session control information of database is obtained.
In step S740, the operation for whether having preordering method in session control information is judged.
If there is the record of the operation of preordering method in the session control information, step S750 is advanced to;If the session There is no the record of the operation of preordering method in control information, advances to step S760.
In step S750, the corresponding SQL statement of operation of preordering method is obtained.
If there is the record of the operation of preordering method in the session control information, the record of the operation of the preordering method is obtained The corresponding SQL statement in part, for subsequent calls.
In step S760, empty information is returned.
In step S770, corresponding Dao is created according to the type of the variable of Bean object and the method name of Bean object The frame of code.
Specifically, using the type of variable in Bean object as the type of this method, according to the variable pair in Bean object The frame of the method for the corresponding Dao code of method name creation party's legitimate name answered.
For example, String getA ()
{ method content }
Wherein, String is the type of variables A in Bean object, and getA is the title for the get function of variables A, side Method content is the specific code of the get method, can be obtained from the session control information in database, the side of method content Method is SQL statement, can be directly called.
In step S780, in the frame of Dao code, for the SQL generation of the call by variable preordering method of Bean object Code is to generate the corresponding Dao code of the preordering method.
Specifically, in the content part of the frame of Dao code, using the variable of Bean object as parameter, above-mentioned acquisition is called Preordering method SQL code, execute the preordering method for Bean object variable predetermined registration operation.
For example, Integer getA (String S)
{ String Str=getsqlsession () .select (A);
return Str;}
Wherein, the Dao code of the above-mentioned getA method for having automatically generated a String type in code, defines one For character type variable Str as return value, the value of the Str is the result after the variables A execution get operation for Bean object. Getsqlsession () method is the method for obtaining session control information, and select (A) is inquiry Bean object variable A SQL statement.
In step S790, in Dao layers of interface classes and realizes and be separately added into the preordering method corresponding Dao generation in class Code.
Specifically, it in interface class and realizes and is separately added into the corresponding Dao code of the preordering method in class, so that the Dao generation Code executes the operation of corresponding preordering method.
It is corresponding according to the SQL statement of preordering method and the corresponding attribute value generation of entity information in step S1400 Mybatis code.
Further, as shown in Figure 10, shown " according to the SQL statement of preordering method and the corresponding attribute value of entity information Generate corresponding Mybatis code " include:
In step S810, the field information of each field in the summary info and the table of table in database is obtained, and will Summary info and field information are converted into the entity information of Java specification.
In step S820, the corresponding attribute value of entity information is determined according to default corresponding relationship.
Specifically, corresponding relationship is preset by this and entity information is converted into the attribute value that SQL is standardized.
For example, the corresponding relationship can be described by table.
Entity information Attribute value Entity information Attribute value
menu_name menuName type type
parent_id parentId …… ……
In above-mentioned table, if entity information is " menu_name ", corresponding attribute value is " menuName ";If entity is believed It is major key that breath, which is set, and entity name of the information is " parent_id ", and corresponding attribute value is " parentId ";If entity Information is " type ", and corresponding attribute value is " type ", etc..
In step S830, the SQL statement of preordering method is obtained.
Further, the session control information that the database is obtained by JDBC technology judges the session control information In whether have the corresponding operation of preordering method, if there is the record of the corresponding operation of preordering method in session control information, obtain should The corresponding SQL statement of preordering method.
In step S840, corresponding Mybatis code is generated according to the SQL statement of attribute value and preordering method.
Specifically, described " generating corresponding Mybatis code according to the SQL statement of attribute value and preordering method " includes:
Using the attribute value as parameter, the SQL statement of the preordering method is called to generate the preordering method corresponding Mybatis code.
Further, as shown in figure 11, shown " according to the SQL statement of preordering method and the corresponding attribute value of entity information Generate corresponding Mybatis code " include:
In step S910, the field information of each field in the summary info and the table of table in database is obtained, and will Summary info and field information are converted into the entity information of Java specification.
In step S920, the corresponding attribute value of entity information is determined according to default corresponding relationship.
In step S930, Mybatis configuration file is generated according to Bean object.
Mybatis layers (i.e. Mybatis SQL layer 14 in Fig. 2) connected between Java Development Framework and database it is important Link, Mybatis layers provide method of servicing upwards for Dao layers and realize, provide the function of attended operation downwards for data.
In step S940, the current session control information of database is obtained.
In step S950, the operation for whether having preordering method in session control information is judged.
If there is the operation note of preordering method in session control information, step S960 is advanced to;If in session control information There is no the operation note of preordering method, advances to step S960a.
In step S960, the SQL statement of preordering method is obtained.
Specifically, if there is the operation note of preordering method in session control information, the preordering method is obtained in this record Corresponding SQL statement.
In step S960a, empty information is returned.
In step S970, the frame of corresponding Mybatis code is created according to the method name of Bean object.
Specifically, according to the corresponding Dao code of the corresponding method name creation party's legitimate name of the variable in Bean object Method frame.
For example,<select id=" get " ...>
Method content
</select>
In step S980, in the frame of Mybatis code, using attribute value as parameter, the SQL language of preordering method is called Sentence generates the corresponding Mybatis code of the preordering method.
Specifically, it in the content part of the frame of Mybatis code, using the variable of Bean object as parameter, calls above-mentioned The SQL code of the preordering method of acquisition executes the preordering method for the predetermined registration operation of the variable of Bean object.
In step S990, added in Mybatis configuration file default mapping table, Bean object variable and Mybatis code.
Specifically, it is added the mapping table in Mybatis configuration file, the variable of Bean object and above-mentioned generation Mybatis code, so that Dao layers are attached by the Mybatis configuration file with database.
Embodiment 2
Figure 12 shows a kind of structural schematic diagram of Service code generating unit provided in an embodiment of the present invention.It should Service code generating unit 100 is applied in Java Development Framework.
The code generating unit 100 includes obtaining module 110, judgment module 120 and generation module 130.
Module 110 is obtained, for obtaining the field information of each field in the summary info of table and the table in database, and Convert the summary info and the field information to the entity information of Java specification, wherein the entity information includes The method name of the variable of Bean object and the Bean object.
Judgment module 120, for whether being stored with preordering method in Java Development Framework where judging Service layers Java code.
Generation module 130, if being stored with the Java of the preordering method where described Service layers in Java Development Framework Code, shown generation module 130 are used for according to the Java code of the preordering method, the variable of the Bean object and described The method name of Bean object generates corresponding Service code.
The present invention also provides a kind of terminal, which may include PC, computer, service Device, tablet computer etc..The terminal includes memory and processor, and the memory is for storing computer journey Sequence, the processor runs the computer program so that the terminal executes the above-mentioned code building side Service The function of modules in method or Service code generating unit.
Memory may include storing program area and storage data area, wherein storing program area can storage program area, at least Application program needed for one function;Storage data area, which can be stored, uses created data according to computer equipment.In addition, Memory may include high-speed random access memory, can also include nonvolatile memory, and a for example, at least disk is deposited Memory device, flush memory device or other volatile solid-state parts.
The present embodiment additionally provides a kind of computer storage medium, described used in above-mentioned terminal for storing Computer program.
So far, the present invention provides a kind of Service code generating method and terminals, grab the summary of table in real time The field information of each field in information, table, and summary info and field information are parsed and identified, it generates corresponding The Bean object of Java specification, the code of generation is unified, style is consistent, improves development efficiency;It is different to prepare JDBC type It causes, corresponding type of database is also different, reduces Developmental Engineer and learns various types of database technologys, reduces study Cost;It is automatic according to Bean object and quickly generate preordering method on the eclispe developing instrument of Java Development Framework Service code, Dao code and Mybatis code avoid developer from writing the repetition work of same code in each project Make, improves developer's working efficiency;The skimble-scamble problem of code as caused by developer's coding style difference is avoided, is mentioned The normalization and uniformity of high Java code improve the success rate of Java code compiling.
In several embodiments provided herein, it should be understood that disclosed device and method can also pass through Other modes are realized.The apparatus embodiments described above are merely exemplary, for example, flow chart and structure in attached drawing Figure shows the system frame in the cards of the device of multiple embodiments according to the present invention, method and computer program product Structure, function and operation.In this regard, each box in flowchart or block diagram can represent a module, section or code A part, a part of the module, section or code includes one or more for implementing the specified logical function Executable instruction.It should also be noted that function marked in the box can also be to be different from the implementation as replacement The sequence marked in attached drawing occurs.For example, two continuous boxes can actually be basically executed in parallel, they are sometimes It can execute in the opposite order, this depends on the function involved.It is also noted that in structure chart and/or flow chart The combination of each box and the box in structure chart and/or flow chart, can function or movement as defined in executing it is dedicated Hardware based system realize, or can realize using a combination of dedicated hardware and computer instructions.
In addition, each functional module or unit in each embodiment of the present invention can integrate one independence of formation together Part, be also possible to modules individualism, an independent part can also be integrated to form with two or more modules. If the function is realized and when sold or used as an independent product in the form of software function module, can store one In a computer-readable storage medium.Based on this understanding, technical solution of the present invention is substantially in other words to existing skill The part of part or the technical solution that art contributes can be embodied in the form of software products, the computer software Product is stored in a storage medium, including some instructions are used so that computer equipment (can be smart phone, a People's computer, server or network equipment etc.) it performs all or part of the steps of the method described in the various embodiments of the present invention. And storage medium above-mentioned includes: that USB flash disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), arbitrary access are deposited The various media that can store program code such as reservoir (RAM, Random Access Memory), magnetic or disk.
The above description is merely a specific embodiment, but scope of protection of the present invention is not limited thereto, any Those familiar with the art in the technical scope disclosed by the present invention, can easily think of the change or the replacement, and should all contain Lid is within protection scope of the present invention.

Claims (10)

1. a kind of Service code generating method, which is characterized in that this method comprises:
Obtain the field information of each field in the summary info and the table of table in database, and by the summary info and described Field information is converted into the entity information of Java specification, wherein the entity information includes the variable of Bean object and described The method name of Bean object;
Whether the Java code of preordering method is stored with where judging Service layers in Java Development Framework;
If the Java code is stored in Java Development Framework where described Service layers, according to the Java code, institute The method name of the variable and the Bean object of stating Bean object generates corresponding Service code.
2. Service code generating method according to claim 1, which is characterized in that it is described " by the summary info and The field information is converted into the entity information of Java specification " include:
The summary info is parsed, and summary parsing information is converted into the Bean object of Java specification;
The field information is parsed, and field parsing information is converted to the variable of the Bean object, then basis The variable of the Bean object generates the method name of the Bean object.
3. Service code generating method according to claim 1, which is characterized in that described " according to the preordering method Java code, the variable of the Bean object and the method name of the Bean object generate corresponding Service code " packet It includes:
The frame of corresponding Service code is created according to the type of the variable of Bean object and the method name of the Bean object Frame;
In the frame of the Service code, the Java generation of preordering method described in the call by variable for the Bean object Code.
4. Service code generating method according to claim 1, which is characterized in that the preordering method is the side get Method, getList method, add method, addSelective method, delete method or update method.
5. Service code generating method according to claim 2, which is characterized in that the summary info of the table includes The title of table and the remark information of table;
" summary info is parsed, and summary parsing information is converted into the Bean object of the Java specification " packet It includes:
It is segmented according to title of the preset rules to the table, each section is converted into the Bean title of predetermined format, and will The Bean object that all sections of Bean name combination is standardized at Java;
Where the remark information to be written to the Bean object in the form of java class remarks in the file of class.
6. Service code generating method according to claim 2, which is characterized in that the field information includes field Title;
It is described " field information to be parsed, and field parsing information is converted to the variable of the Bean object, then The method name of the Bean object is generated according to the variable of the Bean object " include:
The field name is segmented according to preset rules, is Java rule by all sections of content transformation of the field name The name variable of the Bean object of model;
The method name of the Bean object is generated according to the functional circuit information of the name variable and the preordering method.
7. Service code generating method according to claim 2, which is characterized in that further include:
Interface class and realization class of the table at Service layers is respectively created according to the Bean object of the table;
The Service code is separately added into described Service layers of interface class and realization class.
8. Service code generating method according to claim 5 or 6, which is characterized in that the preset rules include:
It is right using the underscore as cut-point if in the title or table of the table in each field name include underscore Each field name is segmented in the title or table of the table;
If in the title or table of the table in each field name include upper and lower case letter, by each capitalization and this is big All lowercases after the mother write are divided into one section.
9. a kind of terminal, which is characterized in that the terminal includes memory and processor, the memory For storing computer program, the processor runs the computer program so that the terminal perform claim requires 1 to 8 described in any item Service code generating methods.
10. a kind of computer storage medium, which is characterized in that it is stored used in terminal described in claim 9 The computer program.
CN201811385948.8A 2018-11-20 2018-11-20 Service code generation method and computer terminal Active CN109542418B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811385948.8A CN109542418B (en) 2018-11-20 2018-11-20 Service code generation method and computer terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811385948.8A CN109542418B (en) 2018-11-20 2018-11-20 Service code generation method and computer terminal

Publications (2)

Publication Number Publication Date
CN109542418A true CN109542418A (en) 2019-03-29
CN109542418B CN109542418B (en) 2022-04-05

Family

ID=65848785

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811385948.8A Active CN109542418B (en) 2018-11-20 2018-11-20 Service code generation method and computer terminal

Country Status (1)

Country Link
CN (1) CN109542418B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110471650A (en) * 2019-07-11 2019-11-19 新华三大数据技术有限公司 A kind of Web Service dissemination method, device and server
CN110704039A (en) * 2019-09-30 2020-01-17 北京三快在线科技有限公司 Configuration data processing method and device in application development process
CN111079188A (en) * 2019-12-27 2020-04-28 苏州海管家物流科技有限公司 mybatis field encryption and decryption device and encryption and decryption system

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140282369A1 (en) * 2013-03-14 2014-09-18 Adminovate, Inc. Software application generator
CN104317576A (en) * 2014-07-04 2015-01-28 北京思特奇信息技术股份有限公司 Code automatic generation method and system based on eclipse
CN105824619A (en) * 2016-03-10 2016-08-03 四川交通职业技术学院 Code generator integrated based on Spring MVC framework, Apache Shiro framework and MyBatis framework
CN106293664A (en) * 2015-05-27 2017-01-04 交通银行股份有限公司 Code generating method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140282369A1 (en) * 2013-03-14 2014-09-18 Adminovate, Inc. Software application generator
CN104317576A (en) * 2014-07-04 2015-01-28 北京思特奇信息技术股份有限公司 Code automatic generation method and system based on eclipse
CN106293664A (en) * 2015-05-27 2017-01-04 交通银行股份有限公司 Code generating method and device
CN105824619A (en) * 2016-03-10 2016-08-03 四川交通职业技术学院 Code generator integrated based on Spring MVC framework, Apache Shiro framework and MyBatis framework

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
HELLO_读书就是赚钱: "如何根据数据库文件自动生成整个bean层与service层", 《HTTPS://BLOG.CSDN.NET/HAYRE/ARTICLE/DETAILS/77103576》 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110471650A (en) * 2019-07-11 2019-11-19 新华三大数据技术有限公司 A kind of Web Service dissemination method, device and server
CN110471650B (en) * 2019-07-11 2022-08-09 新华三大数据技术有限公司 Web Service publishing method, device and server
CN110704039A (en) * 2019-09-30 2020-01-17 北京三快在线科技有限公司 Configuration data processing method and device in application development process
CN111079188A (en) * 2019-12-27 2020-04-28 苏州海管家物流科技有限公司 mybatis field encryption and decryption device and encryption and decryption system
CN111079188B (en) * 2019-12-27 2022-04-15 苏州海管家物流科技有限公司 mybatis field encryption and decryption device and encryption and decryption system

Also Published As

Publication number Publication date
CN109542418B (en) 2022-04-05

Similar Documents

Publication Publication Date Title
CN109471619A (en) Mybatis code generating method, device and terminal
US8438190B2 (en) Generating web services from business intelligence queries
CN105511873B (en) User interface control display method and device
US8275775B2 (en) Providing web services from business intelligence queries
US20090077074A1 (en) Apparatus, computer program product, and method for supporting construction of ontologies
US9552441B2 (en) Database mapping of models for reporting tools in model driven development
US8701087B2 (en) System and method of annotating class models
CN109582647B (en) Unstructured evidence file oriented analysis method and system
JP2000148461A (en) Software model and existing source code synchronizing method and device
CN109542418A (en) Service code generating method and terminal
CN106951231B (en) Computer software development method and device
CN107609302B (en) Method and system for generating product process structure
WO2018233673A1 (en) Method and apparatus for configuring model code in controller, and storage medium
CN106469223A (en) A kind of compatibility space of ArcGIS and the unified control method of attribute data and system
CN106776779B (en) Method for generating entity file by JSON data based on Mac platform
CN109542453A (en) Database information recognition methods, device and terminal
CN113094039B (en) Automatic code generation system based on database table
CN114820881A (en) Picture generation method, intelligent terminal and computer readable storage medium thereof
CN109740138A (en) A kind of editable method of picture file in realization mind map software
CN109491649A (en) Dao code generating method and terminal
CN110347878B (en) Rule engine driven data fusion method
CN102486731B (en) Strengthen the visualization method of the call stack of software of software, equipment and system
CN115374764A (en) Demand model automatic generation method and system based on user story
CN111831288B (en) Method and system for automatically generating Thrift IDL data structure and automatic transfer function
CN113934748A (en) Mixed type SQL script file generation method, execution method and 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
GR01 Patent grant
GR01 Patent grant