CN109471619A - Mybatis code generating method, device and terminal - Google Patents

Mybatis code generating method, device and terminal Download PDF

Info

Publication number
CN109471619A
CN109471619A CN201811386000.4A CN201811386000A CN109471619A CN 109471619 A CN109471619 A CN 109471619A CN 201811386000 A CN201811386000 A CN 201811386000A CN 109471619 A CN109471619 A CN 109471619A
Authority
CN
China
Prior art keywords
code
mybatis
information
field
preordering
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
Application number
CN201811386000.4A
Other languages
Chinese (zh)
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 CN201811386000.4A priority Critical patent/CN109471619A/en
Publication of CN109471619A publication Critical patent/CN109471619A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse
    • 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
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a kind of Mybatis code generating method, device and terminals, this method comprises: obtaining the field information of each field in the summary info and the table of 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 variable of Bean object and the method name of the Bean object;The corresponding attribute value of the entity information is determined according to default mapping table;Obtain the SQL statement of preordering method;Corresponding Mybatis code is generated according to the SQL statement of the attribute value and the preordering method.Technical solution of the present invention, Mybatis code that is automatic using database information and quickly generating preordering method, avoids developer from writing the repeated work of same code in each project, improves the uniformity of developer's working efficiency and code.

Description

Mybatis code generating method, device and terminal
Technical field
The present invention relates to Java development technique fields, in particular to a kind of Mybatis code generating method, device And 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 be designed to provide a kind of Mybatis code generating method, device and Terminal, so as to solve the deficiencies in the prior art.
According to embodiment of the present invention, a kind of Mybatis code generating method is provided 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;
The corresponding attribute value of the entity information is determined according to default mapping table;
Obtain the SQL statement of preordering method;
Corresponding Mybatis code is generated according to the SQL statement of the attribute value and the preordering method.
It is described " to obtain in database in the summary info and the table of table in above-mentioned Mybatis code generating method Before the field information of each field " further include:
SQL query statement is sent to the database by JDBC, the summary of table in database is obtained according to query result The field information of each field in information and the table.
In above-mentioned Mybatis code generating method, the preordering method is get method, add method or the side update Method.
In above-mentioned Mybatis code generating method, " SQL statement for obtaining preordering method " includes:
Obtain the current session control information of the database;
Judge the operation for whether having the preordering method in the session control information;
If there is the operation of the preordering method in the session control information, the operation for obtaining the preordering method is corresponding SQL statement;
If there is no the operation of the preordering method in the session control information, empty information is returned.
It is described " according to the attribute value and the SQL of the preordering method in above-mentioned Mybatis code generating method Sentence generates corresponding Mybatis code " include:
The frame of corresponding Mybatis code is created according to the method name of the Bean object;
In the frame of the Mybatis code, using the attribute value as parameter, the SQL language of the preordering method is called Sentence generates the corresponding Mybatis code of the preordering method.
It is described " to convert the summary info and the field information in above-mentioned Mybatis 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, with carry out the preordering method code it is automatic It generates.
In above-mentioned Mybatis code generating method, further includes:
Mybatis configuration file is generated according to the Bean object;
The default mapping table, the variable of the Bean object and institute are added in the Mybatis configuration file State Mybatis code.
According to another implementation of the invention, a kind of Mybatis code generating unit is provided, which includes:
Conversion module, 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;
Determining module, for determining the corresponding attribute value of the entity information according to default mapping table;
Module is obtained, for obtaining the SQL statement of preordering method;
Generation module, for generating corresponding Mybatis generation according to the SQL statement of the attribute value and the preordering method 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 Mybatis 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 Mybatis code generating method, device and terminal in the present invention, automatically simultaneously according to database information The Mybatis code for quickly generating preordering method, avoids developer from writing the repeated work of same code in each project, Improve developer's working efficiency;The skimble-scamble problem of code as caused by developer's coding style difference is avoided, is improved The normalization and uniformity of Mybatis code improve the success rate of Mybatis 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 Mybatis code generating method provided in an embodiment of the present invention.
Fig. 3 shows the flow diagram of another kind Mybatis 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 the second preset rules to title provided in an embodiment of the present invention and shows It is intended to.
Fig. 8 shows a kind of flow diagram of Service code generating method provided in an embodiment of the present invention.
Fig. 9 shows the flow diagram of another kind Service code generating method provided in an embodiment of the present invention.
Figure 10 shows a kind of flow diagram of Dao code generating method provided in an embodiment of the present invention.
Figure 11 shows the flow diagram of another kind Dao code generating method provided in an embodiment of the present invention.
Figure 12 shows a kind of structural schematic diagram of Mybatis 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-Mybatis code generating unit;110- conversion module;120- determining module;130- obtains module;140- is raw At 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
Fig. 1 shows a kind of flow diagram of Mybatis code generating method provided in an embodiment of the present invention.It should Mybatis code generating method is applied in Java Development Framework.
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, being a kind of flow diagram of Mybatis code generating method provided in an embodiment of the present invention.
The Mybatis code generating method includes the following steps:
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.
As shown in figure 3, being the flow diagram of another kind Mybatis code generating method provided in an embodiment of the present invention.
The Mybatis code generating method includes the following steps:
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.
As shown in figure 4, being a kind of flow diagram of code generating method provided in an embodiment of the present invention, the code building 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 Mybatis 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 method name of the name variable of Bean object and Bean object.
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 second preset rules to table, is converted into pre- fix for each section The Bean title of formula, and the Bean object that all sections of Bean name combination is standardized at Java.
Further, as shown in fig. 7, second 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.
Include two kinds of situations if at least condition A is set up: only condition A is set up or condition A, condition B are set up, and is advanced to Step S330;If condition A, condition B are invalid, step S360 is advanced to;If only condition B is set up, step S340 is advanced to.
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 section.
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 section.
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 the second preset rules, by the field All sections of content transformations of title are the name variable of the Bean object of predetermined format.
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 method name of Bean object according to the first preset rules, with root The code of preordering method is automatically generated according to the method name of name variable, Java regulating style and Bean object.
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 method name of description information and the variable as the Bean object.
Specifically, by the method name format of the Bean object is defined as: the functional circuit information+Bean of preordering method The title of the variable of object.
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.
Further, as shown in figure 8, it is described " according to the Java code of preordering method, the variable of Bean object and Bean pairs The method name of elephant generates corresponding Service code " include:
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, 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.
Specifically, described " according to the Java code of the preordering method, the variable of the Bean object and Bean pairs described The method name of elephant generates 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.
Further, as shown in figure 9, it is described " according to the Java code of preordering method, the variable of Bean object and Bean pairs The method name of elephant generates corresponding Service code " include:
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.
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 10, 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 11, 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.
Embodiment 2
Figure 12 shows a kind of structural schematic diagram of Mybatis code generating unit provided in an embodiment of the present invention.It should Mybatis code generating unit 100 is applied in Java Development Framework.
The Mybatis code generating unit 100 includes conversion module 110, determining module 120, obtains module 130 and generate Module 140.
Conversion module 110, 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.
Determining module 120, for determining the corresponding attribute value of the entity information according to default mapping table.
Module 130 is obtained, for obtaining the SQL statement of preordering method.
Generation module 140, it is corresponding for being generated according to the SQL statement of the attribute value and the preordering method Mybatis 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 Mybatis The function of modules in method or Mybatis 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 Mybatis code generating method, device and terminal, table is grabbed in real time Summary info, in table each field field information, and summary info and field information are parsed and are identified, generated therewith The Bean object of corresponding Java specification, the code of generation is unified, style is consistent, improves development efficiency;Prepare JDBC class Type is inconsistent, and corresponding type of database is also different, reduces Developmental Engineer and learns various types of database technologys, subtracts Few learning cost;It is automatic according to Bean object and quickly generate predetermined party on the eclispe developing instrument of Java Development Framework Service code, Dao code and the Mybatis code of method, avoid developer from writing the weight of same code in each project It returns to work work, improves developer's working efficiency;Avoid code is skimble-scamble as caused by developer's coding style difference from asking Topic improves the normalization and uniformity of Java code, improves 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 Mybatis 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;
The corresponding attribute value of the entity information is determined according to default mapping table;
Obtain the SQL statement of preordering method;
Corresponding Mybatis code is generated according to the SQL statement of the attribute value and the preordering method.
2. Mybatis code generating method according to claim 1, which is characterized in that described " to obtain table in database Before the field information of each field in summary info and the table " further include:
SQL query statement is sent to the database by JDBC, the summary info of table in database is obtained according to query result And in the table each field field information.
3. Mybatis code generating method according to claim 1, which is characterized in that the preordering method is the side get Method, add method or update method.
4. Mybatis code generating method according to claim 1, which is characterized in that described " to obtain preordering method SQL statement " includes:
Obtain the current session control information of the database;
Judge the operation for whether having the preordering method in the session control information;
If there is the operation of the preordering method in the session control information, the corresponding SQL of operation of the preordering method is obtained Sentence;
If there is no the operation of the preordering method in the session control information, empty information is returned.
5. Mybatis code generating method according to claim 1, which is characterized in that it is described " according to the attribute value and The SQL statement of the preordering method generates corresponding Mybatis code " include:
The frame of corresponding Mybatis code is created according to the method name of the Bean object;
In the frame of the Mybatis code, using the attribute value as parameter, call the SQL statement of the preordering method raw At the corresponding Mybatis code of the preordering method.
6. Mybatis 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, to carry out the automatic life of the code of the preordering method At.
7. Mybatis code generating method according to claim 6, which is characterized in that further include:
Mybatis configuration file is generated according to the Bean object;
The default mapping table, the variable of the Bean object and described are added in the Mybatis configuration file Mybatis code.
8. a kind of Mybatis code generating unit, which is characterized in that the device includes:
Conversion module, for obtaining the field information of each field in the summary info of table and the table in database, and will be described Summary info and the field information are converted into the entity information of Java specification, wherein the entity information includes Bean object Variable and the Bean object method name;
Determining module, for determining the corresponding attribute value of the entity information according to default mapping table;
Module is obtained, for obtaining the SQL statement of preordering method;
Generation module, for generating corresponding Mybatis code according to the SQL statement of the attribute value and the preordering method.
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 7 described in any item Mybatis 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.
CN201811386000.4A 2018-11-20 2018-11-20 Mybatis code generating method, device and terminal Pending CN109471619A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811386000.4A CN109471619A (en) 2018-11-20 2018-11-20 Mybatis code generating method, device and terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811386000.4A CN109471619A (en) 2018-11-20 2018-11-20 Mybatis code generating method, device and terminal

Publications (1)

Publication Number Publication Date
CN109471619A true CN109471619A (en) 2019-03-15

Family

ID=65673799

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811386000.4A Pending CN109471619A (en) 2018-11-20 2018-11-20 Mybatis code generating method, device and terminal

Country Status (1)

Country Link
CN (1) CN109471619A (en)

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110275702A (en) * 2019-06-27 2019-09-24 浪潮卓数大数据产业发展有限公司 A kind of presentation layer data format system of Java Web project
CN110442596A (en) * 2019-07-30 2019-11-12 北京明略软件系统有限公司 Acquisition methods, device, storage medium and the electronic device of database information
CN110531971A (en) * 2019-08-29 2019-12-03 深圳市今天国际物流技术股份有限公司 Fetcher code automatic generation method, device, computer equipment and storage medium
CN111079188A (en) * 2019-12-27 2020-04-28 苏州海管家物流科技有限公司 mybatis field encryption and decryption device and encryption and decryption system
CN111078205A (en) * 2019-11-22 2020-04-28 北京锐安科技有限公司 Modular programming method and device, storage medium and electronic equipment
CN112114794A (en) * 2020-09-27 2020-12-22 江西宜月鑫网络科技有限公司 Automatic generation method and device of website application program and computer storage medium
CN112346720A (en) * 2020-10-22 2021-02-09 杭州安恒信息技术股份有限公司 Method, equipment and electronic device for generating custom code based on sql
CN112905453A (en) * 2021-02-03 2021-06-04 重庆富民银行股份有限公司 Method for quickly generating database operation code in automatic test
CN113656036A (en) * 2020-05-12 2021-11-16 深圳兆日科技股份有限公司 Compiling method, device, terminal and medium based on Mybatis
CN113704225A (en) * 2021-08-20 2021-11-26 济南浪潮数据技术有限公司 Method, system, equipment and storage medium for constructing and using configuration center
CN114756554A (en) * 2022-06-13 2022-07-15 中建电子商务有限责任公司 Data query processing method based on MyBatis framework

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102566990A (en) * 2010-12-09 2012-07-11 北大方正集团有限公司 Method and device for performing data manipulation in Java application
CN105824619A (en) * 2016-03-10 2016-08-03 四川交通职业技术学院 Code generator integrated based on Spring MVC framework, Apache Shiro framework and MyBatis framework
CN107391153A (en) * 2017-07-31 2017-11-24 深圳乐信软件技术有限公司 A kind of code generating method and device based on Spring Yu MyBatis framework integrations
CN107479883A (en) * 2017-08-07 2017-12-15 海闻科技有限公司 A kind of code generating method and code generator

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102566990A (en) * 2010-12-09 2012-07-11 北大方正集团有限公司 Method and device for performing data manipulation in Java application
CN105824619A (en) * 2016-03-10 2016-08-03 四川交通职业技术学院 Code generator integrated based on Spring MVC framework, Apache Shiro framework and MyBatis framework
CN107391153A (en) * 2017-07-31 2017-11-24 深圳乐信软件技术有限公司 A kind of code generating method and device based on Spring Yu MyBatis framework integrations
CN107479883A (en) * 2017-08-07 2017-12-15 海闻科技有限公司 A kind of code generating method and code generator

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
文欢欢等: "基于Mybatis和JDBC的分页查询研究", 《计算机工程应用技术》 *

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110275702B (en) * 2019-06-27 2022-07-26 浪潮卓数大数据产业发展有限公司 Presentation layer data formatting system of Java Web project
CN110275702A (en) * 2019-06-27 2019-09-24 浪潮卓数大数据产业发展有限公司 A kind of presentation layer data format system of Java Web project
CN110442596A (en) * 2019-07-30 2019-11-12 北京明略软件系统有限公司 Acquisition methods, device, storage medium and the electronic device of database information
CN110531971A (en) * 2019-08-29 2019-12-03 深圳市今天国际物流技术股份有限公司 Fetcher code automatic generation method, device, computer equipment and storage medium
CN110531971B (en) * 2019-08-29 2023-01-03 深圳市今天国际物流技术股份有限公司 Automatic generation method and device of access code, computer equipment and storage medium
CN111078205A (en) * 2019-11-22 2020-04-28 北京锐安科技有限公司 Modular programming method and device, storage medium and electronic equipment
CN111078205B (en) * 2019-11-22 2024-01-26 北京锐安科技有限公司 Modularized programming method and device, storage medium and electronic equipment
CN111079188A (en) * 2019-12-27 2020-04-28 苏州海管家物流科技有限公司 mybatis field encryption and decryption device and encryption and decryption system
CN113656036A (en) * 2020-05-12 2021-11-16 深圳兆日科技股份有限公司 Compiling method, device, terminal and medium based on Mybatis
CN113656036B (en) * 2020-05-12 2024-03-01 深圳兆日科技股份有限公司 Compiling method, device, terminal and medium based on Mybatis
CN112114794B (en) * 2020-09-27 2021-11-09 深圳天玑数据有限公司 Automatic generation method and device of website application program and computer storage medium
CN112114794A (en) * 2020-09-27 2020-12-22 江西宜月鑫网络科技有限公司 Automatic generation method and device of website application program and computer storage medium
CN112346720A (en) * 2020-10-22 2021-02-09 杭州安恒信息技术股份有限公司 Method, equipment and electronic device for generating custom code based on sql
CN112905453A (en) * 2021-02-03 2021-06-04 重庆富民银行股份有限公司 Method for quickly generating database operation code in automatic test
CN113704225A (en) * 2021-08-20 2021-11-26 济南浪潮数据技术有限公司 Method, system, equipment and storage medium for constructing and using configuration center
CN113704225B (en) * 2021-08-20 2024-02-13 济南浪潮数据技术有限公司 Method, system, device and storage medium for constructing and using configuration center
CN114756554A (en) * 2022-06-13 2022-07-15 中建电子商务有限责任公司 Data query processing method based on MyBatis framework

Similar Documents

Publication Publication Date Title
CN109471619A (en) Mybatis code generating method, device and terminal
US8438190B2 (en) Generating web services from business intelligence queries
US8418125B2 (en) Incremental model refinement and transformation in generating commerce applications using a model driven architecture
US7912826B2 (en) Apparatus, computer program product, and method for supporting construction of ontologies
CN105511873B (en) User interface control display method and device
US8275775B2 (en) Providing web services from business intelligence queries
US9552441B2 (en) Database mapping of models for reporting tools in model driven development
US20110023022A1 (en) Method for application authoring employing an application template stored in a database
US8701087B2 (en) System and method of annotating class models
JP2005521159A (en) Dynamic generation of schema information for data description languages
CN106951231B (en) Computer software development method and device
CN109542418A (en) Service code generating method and terminal
CN109542453A (en) Database information recognition methods, device and terminal
CN106776779B (en) Method for generating entity file by JSON data based on Mac platform
CN113094039B (en) Automatic code generation system based on database table
CN113655996A (en) Enterprise-level system generation method based on demand model
CN109491649A (en) Dao code generating method and terminal
CN110347878B (en) Rule engine driven data fusion method
CN117193738A (en) Application building method, device, equipment and storage medium
CN115374764A (en) Demand model automatic generation method and system based on user story
CN112114812B (en) Grammar checking method applied to industrial robot programming language
CN113934748A (en) Mixed type SQL script file generation method, execution method and device
US8719693B2 (en) Method for storing localized XML document values
CN117289905B (en) Application software development method and device, storage medium and electronic equipment
US8732212B2 (en) System for simplifying an XML-based schema

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20190315

RJ01 Rejection of invention patent application after publication