Modular programming method and device, storage medium and electronic equipment
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a modular programming method, a modular programming device, a storage medium and electronic equipment.
Background
With the continuous development of computer technology, JAVA technology becomes an important technology for project development. For conventional Java project development, background codes are designed by using a layered architecture, and a plurality of open-source frameworks need to be integrated due to the fact that the project is designed by using a layered structure; common background frames are integrated based on SpringBoot + Spring + SpringMVC + Mybatis, the Spring provides a container to realize management and dependence injection of Javabean, the SpringMVC provides a Web request interface, and the MyBatis provides operation on a database.
However, in the development process of the Java project, the code needs to be written manually by a developer, which causes a large workload and low development efficiency.
Disclosure of Invention
The invention provides an invention name, and aims to realize a modular programming method, a device, a storage medium and electronic equipment.
In a first aspect, an embodiment of the present invention provides a modular programming method, including:
acquiring a database table and service requirements;
creating a preset program module, and determining a basic program corresponding to the service requirement in the preset program module;
and updating the basic program in each program module according to the field data in the database table to generate a target program.
In a second aspect, an embodiment of the present invention further provides a modular programming apparatus, including:
the database table acquisition module is used for acquiring a database table and service requirements;
a preset program module creating module for creating a preset program module in which a basic program corresponding to the service demand is determined;
and the target program generation module is used for updating the basic program in each program module according to the field data in the database table to generate a target program.
In a third aspect, an embodiment of the present invention further provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the computer program to implement a modular programming method according to any embodiment of the present invention.
In a fourth aspect, embodiments of the present invention further provide a storage medium containing computer-executable instructions, where the computer-executable instructions, when executed by a computer processor, implement a modular programming method as provided in any of the embodiments of the present invention.
According to the technical scheme, the database table containing the field data and the service requirement of the target program are obtained, the preset program module in the electronic equipment is called, the basic program corresponding to the service requirement in the preset program module is determined, and the target program capable of meeting the service requirement is generated by adding the field data in the database table to the corresponding position of the basic program in each preset program module. Based on the technical scheme, developers of the target program only need to complete the design of the database table, and the target program can be generated based on the database table by one key, so that code writing of developers is reduced, and multiplexing and development efficiency of basic programs are improved.
Drawings
Fig. 1 is a schematic flowchart of a modular programming method according to an embodiment of the present invention;
FIG. 2 is a diagram of a database table according to an embodiment of the present invention;
FIG. 3 is a diagram of a created default program module according to an embodiment of the present invention;
FIG. 4 is a schematic structural diagram of a modular programming apparatus according to a second embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to a third embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a schematic flowchart of a modular programming method according to an embodiment of the present invention, where the present embodiment is applicable to a case of implementing fast programming, and the method may be executed by a modular programming apparatus according to an embodiment of the present invention, where the apparatus may be implemented in a software and/or hardware manner, and the method specifically includes the following steps:
and S110, acquiring a database table and a service requirement.
S120, creating a preset program module, and determining a basic program corresponding to the service requirement in the preset program module.
And S130, updating the basic program in each program module according to the field data in the database table to generate a target program.
In this embodiment, modular programming is performed in a Spring boot + Spring mvc + Mybatis framework. The target program automatically generated based on the modular programming method is suitable for creating a table with specific functions for storing data in a database.
The database table is a table set according to business requirements, and includes data fields required for generating an object program, for example, refer to fig. 2, and fig. 2 is a schematic diagram of a database table provided in an embodiment of the present invention. As can be seen from fig. 2, the database table includes fields "user CID", "name", "age", and "creation time", and description information of each field.
The database table may be stored locally, may be input externally, or may be generated based on parameters input externally. Optionally, the obtaining a database table includes: acquiring creation parameters of a database table, and creating the database table in the database according to the creation parameters of the database table, wherein the creation parameters of the database table comprise a database table name and field contents in the database. In this embodiment, after the creation parameter of the database table is obtained, according to the database table creation instruction, the database table creation statement is called, the creation statement is executed, and the database table is created. Specifically, a first table creation statement corresponding to the database table name is called and executed, and an initial database table is created in the database; and calling and executing a second table creation statement corresponding to the field content, adding field data corresponding to the field content in the initial database table, and generating a database table.
Illustratively, the SQL statement (Structured Query Language) that creates a database table may be:
create table TB_USERINFO
(
user_cid VARCHAR2(100),
name VARCHAR2(100),
age VARCHAR2(100),
create_time DATE
);
--Add comments to the columns
comment on column TB_USERINFO.user_cid
is 'user CID';
comment on column TB_USERINFO.name
is 'name';
comment on column TB_USERINFO.age
is 'age';
comment on column TB_USERINFO.create_time
is 'creation time';
executing the above create statement can result in a database table as shown in fig. 2. Wherein the name of the database table is TB _ USERNINFO. Where the name of a database table includes a prefix and a table name, and is separated by an underline, if the table name includes multiple words, the words are separated by an underline, for example, the name in fig. 2 is USERINFO.
In this embodiment, the service requirement is a function of a table created in the database, and may be, for example, an addition function, a deletion function, a modification function, a search function, and the like. In some embodiments, business requirements may include, but are not limited to, page turning, paging queries, data checking, view details, add/modify page turning, data saving, data updating, data deletion, data export, and the like.
After the database table and the service requirement are obtained, a target program generating instruction is received, and a preset program module is created according to the target program generating instruction. The target program generation instruction may be input by an operator through a key, a virtual control, a touch gesture, or voice. Optionally, the preset program module includes: the system comprises a data block access object DAO layer, an interface service action layer, a database entity bean layer, a configuration file config layer and a service logic service layer, wherein the preset program modules are configured with at least one basic program, and a dependency relationship is set among the preset program modules. The DAO layer is an object-oriented database interface and is arranged between the business logic layer and the database resources. The database entity bean layer is used for storing entity classes, the configuration file config layer is used for storing mapping files of mybatis, operation functions based on addition, deletion, modification, checking and the like are defined in the mapping files of the mybatis, and for example, see table 1, where table 1 is the operation function defined in the mapping files of the mybatis. The service layer of the service logic comprises service processing logic, and the interface service action layer is used for providing a data interface with the outside.
The method comprises the steps of creating preset program modules according to target program generation instructions, and generating names of the preset program modules, wherein the names of the preset program modules are determined according to table names of a database table. Illustratively, the table name of the database table in fig. 2 is USERINFO, and the name of the DAO layer of the data block access object and the name of the bean layer of the database entity may be the same as the table name of the database table, for example, USERINFO; the naming mode of the configuration file config layer is as follows: xml, the database type _ JavaBean class name _ mapper, which may be, for example: xml, wherein the name of the JavaBean class is the name of a bean layer of the database entity; the naming mode of the Service layer of the Service logic is class name + Service, wherein the class name is the same as the table name of the database table, and can be illustratively UserInfoservice; the interface service Action layer is named by JavaBean class name + Action, which can be UserInfoaction as an example. In this embodiment, names of the preset program modules are generated according to the table name of the database table, so that the mapping relationship between the preset program modules is reduced. Illustratively, referring to fig. 3, fig. 3 is a schematic diagram of a created preset program module according to an embodiment of the present invention.
Optionally, the attribute names in the database entity bean layer and the field names of the database table are kept the same, and the fields in the database entity bean layer and the fields of the database table are kept the same, so as to reduce the configuration of field mapping in the mapping file of mybatis.
In this embodiment, each preset program module is configured with at least one basic program, and the basic program adapted to the current service can be determined according to the current service requirement. Optionally, the interface service action layer and the configuration file config layer respectively include a plurality of basic programs, where each basic program corresponds to an operation action of a different database, that is, a service requirement, and the interface service action layer may illustratively include but is not limited to a page turning program, a paging query program, a data verification program, a detail viewing program, a newly added/modified page turning program, a data saving program, a data updating program, a data deleting program, and a data exporting program. Taking the page turning program as an example, the following steps can be taken:
@RequestMapping(“/{pageName}”)
Public String index(@PathVeriable(“pageName”)String pageName,UserInfobean)
and determining to call in a basic program stored in the electronic equipment according to the service requirement input from the outside, and generating a preset program module.
In this embodiment, the generated target program is a JAVA program, and accordingly, a field in the database table needs to be converted into a JAVA attribute field. Optionally, after the database table is obtained, the field data in the database table is read, and the field data in the database table is converted into JAVA attribute field data based on the mapping relationship between the table field and the JAVA attribute field. The field data may be read from the database table by calling a data reading statement and executing the data reading statement, and the data reading statement may be, for example:
SELECT*FROM(SELECT COLUMN_NAME,COMMENTS FROM USER_COL_COMMENTS CWHERE C.TABLE_NAME='TB_USERINFO')T1 LEFT JOIN USER_TAB_COLUMNS T ONT.COLUMN_NAME=T1.COLUMN_NAME WHERE T.TABLE_NAME='TB_USERINFO'
the tables user _ tab _ columns and user _ column _ references are database-specific tables for storing fields and field attributes of the database tables.
The electronic device stores a mapping relationship between a table field and a JAVA attribute field, which may be, for example:
it should be noted that the mapping relationship between the table field and the JAVA attribute field is only an example, and the mapping relationship between the table field and the JAVA attribute field may be edited, such as added, deleted, modified, and the like according to the service requirement.
Optionally, converting field data in the database table into JAVA attribute field data based on a mapping relationship between the table field and the JAVA attribute field, including: determining a conversion statement in a mapping relation between the table field and a JAVA attribute field according to the field attribute of the field data in the database table; and executing the conversion statement, and converting the field data in the database table into JAVA attribute field data. Correspondingly, updating the basic program in each program module according to the field data in the database table includes: and adding the JAVA attribute field data to the basic program in each program module.
Taking a service layer of a service logic as an example, the target program of the service layer generated by adding JAVA attribute field data may be:
on the basis of the above embodiment, the preset program module further includes a Web layer, where the Web layer is configured to render the database table on the display interface, establish an association relationship between each preset program module and the Web layer when each preset program module is created, and render the table corresponding to the target program created in the database on the display interface, so as to implement interaction with an operator.
According to the technical scheme of the embodiment, the preset program module in the electronic equipment is called by acquiring the database table containing the field data and the business requirements of the target program, the basic program corresponding to the business requirements in the preset program module is determined, and the target program capable of meeting the business requirements is generated by adding the field data in the database table to the corresponding position of the basic program in each preset program module. Based on the technical scheme, developers of the target program only need to complete the design of the database table, and the target program can be generated based on the database table by one key, so that code writing of developers is reduced, and multiplexing and development efficiency of basic programs are improved.
Example two
Fig. 4 is a schematic structural diagram of a modular programming apparatus according to a second embodiment of the present invention, where the apparatus includes:
a database table obtaining module 210, configured to obtain a database table and service requirements;
a preset program module creating module 220 configured to create a preset program module in which a basic program corresponding to the service requirement is determined;
and the target program generating module 230 is configured to update the basic program in each program module according to the field data in the database table, so as to generate a target program.
Optionally, the database table obtaining module 210 includes:
the creating parameter acquiring unit is used for acquiring creating parameters of the database table;
and the database table creating unit is used for creating a database table in a database according to the creating parameters of the database table, wherein the creating parameters of the database table comprise the name of the database table and the field content in the database.
Optionally, the database table creating unit is configured to:
calling and executing a first table creation statement corresponding to the database table name, and creating an initial database table in a database;
and calling and executing a second table creation statement corresponding to the field content, adding field data corresponding to the field content in the initial database table, and generating a database table.
Alternatively to this, the first and second parts may,
before the updating the basic program in each program module according to the field data in the database table, the method further includes:
the field data reading module is used for reading field data in the database table;
the field conversion module is used for converting the field data in the database table into JAVA attribute field data based on the mapping relation between the table field and the JAVA attribute field;
accordingly, the object generation module 230 is configured to: and adding the JAVA attribute field data to the basic program in each program module.
Optionally, the field conversion module is configured to:
determining a conversion statement in a mapping relation between the table field and a JAVA attribute field according to the field attribute of the field data in the database table;
and executing the conversion statement, and converting the field data in the database table into JAVA attribute field data.
Optionally, the preset program module includes: the system comprises a data block access object DAO layer, an interface service action layer, a database entity bean layer, a configuration file config layer and a service logic service layer, wherein the preset program modules are configured with at least one basic program, and a dependency relationship is set among the preset program modules.
Optionally, the preset program module further includes a Web layer, and the Web layer is configured to render the database table on a display interface.
The modular programming device provided by the embodiment of the invention can execute the modular programming method provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects for executing the modular programming method.
EXAMPLE III
Fig. 5 is a schematic structural diagram of an electronic device according to a third embodiment of the present invention. FIG. 5 illustrates a block diagram of an exemplary electronic device 12 suitable for use in implementing embodiments of the present invention. The electronic device 12 shown in fig. 5 is only an example and should not bring any limitation to the function and the scope of use of the embodiment of the present invention.
As shown in FIG. 5, electronic device 12 is embodied in the form of a general purpose computing device. The components of electronic device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that couples various system components including the system memory 28 and the processing unit 16.
Bus 18 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, and a processor or local bus using any of a variety of bus architectures. By way of example, such architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, micro-channel architecture (MAC) bus, enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Electronic device 12 typically includes a variety of computer system readable media. Such media may be any available media that is accessible by electronic device 12 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM)30 and/or cache memory 32. The electronic device 12 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from and write to non-removable, nonvolatile magnetic media (not shown in FIG. 5, and commonly referred to as a "hard drive"). Although not shown in FIG. 5, a magnetic disk drive for reading from and writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk") and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 by one or more data media interfaces. Memory 28 may include at least one program product having a set of program modules that are configured to carry out the functions of embodiments of the invention.
A program/utility 44 having a set of program modules 46 may be stored, for example, in memory 28, such program modules 46 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which examples or some combination thereof may comprise an implementation of a network environment. Program modules 46 generally carry out the functions and/or methodologies of the described embodiments of the invention.
Electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), with one or more devices that enable a user to interact with electronic device 12, and/or with any devices (e.g., network card, modem, etc.) that enable electronic device 12 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 22. Also, the electronic device 12 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the Internet) via the network adapter 20. As shown, the network adapter 20 communicates with other modules of the electronic device 12 via the bus 18. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
The processing unit 16 executes various functional applications and data processing by executing programs stored in the system memory 28, for example, to implement a modular programming method provided by an embodiment of the present invention, the method including:
acquiring a database table and service requirements;
creating a preset program module, and determining a basic program corresponding to the service requirement in the preset program module;
and updating the basic program in each program module according to the field data in the database table to generate a target program.
The processing unit 16 executes various functional applications and data processing by executing programs stored in the system memory 28, for example, to implement a modular programming method provided by an embodiment of the present invention.
Of course, those skilled in the art will appreciate that the processor may also implement the solution of a modular programming method provided in any of the embodiments of the present invention.
Example four
The fourth embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a modular programming method provided in the fourth embodiment of the present invention, where the method includes:
acquiring a database table and service requirements;
creating a preset program module, and determining a basic program corresponding to the service requirement in the preset program module;
and updating the basic program in each program module according to the field data in the database table to generate a target program.
Of course, the computer program stored on the computer-readable storage medium provided by the embodiments of the present invention is not limited to the above method operations, and may also perform related operations in a modular programming method provided by any embodiments of the present invention.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, or device.
A computer readable signal medium may include a video clip, feature encoding of a second video, feature encoding of respective video clips, etc., having computer readable program code embodied therein. Such forms of the broadcast video clip, feature encoding of the second video, feature encoding of each video clip, and the like. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, or the like, as well as conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It should be noted that, in the embodiment of the video processing apparatus, the modules included in the embodiment are only divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.