Code generation method and system based on table structure, server and medium
By parsing table structures and recognizing field semantics in enterprise application software development, code that integrates front-end and back-end is generated, solving the problem of insufficient generation capabilities in existing technologies and realizing an efficient and standardized code generation and development process.
Patent Information
- Application Number
- CN202511603414.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-04
- Publication Date
- 2026-01-23
AI Technical Summary
Existing technologies for enterprise application software development suffer from problems such as incomplete generation capabilities, difficulty in flexibly customizing templates, the need for extensive manual modifications to front-end and back-end binding, and difficulty in generating results that meet enterprise standards, leading to low development efficiency.
By parsing the table structure of the preset data source, identifying field semantics, determining the front-end control type and back-end validation rules, calling the code template to generate the original code, binding the front-end and back-end interfaces, and generating the target code.
It achieves intelligent mapping of front-end and back-end code elements, improves the adaptability of code to business scenarios, reduces development workload and time costs, ensures the consistency of code style and architecture specifications, reduces interface connection errors, and improves system maintainability and team collaboration efficiency.
Smart Images

Figure CN121387300A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a code generation method and system based on table structure, a server and a medium. BACKGROUND
[0002] In the field of enterprise-level application software development, especially in the development of management information system based on Browser / Server (B / S) architecture, developing function modules with relational database as the core is a common and mature mode. The usual development process is: the developer first designs or obtains the table structure of the database, and then manually writes the entity class, data access layer, business logic layer and control layer of the backend based on the table structure. Subsequently, the front-end developer manually writes the front-end page according to the interface document. This results in a lot of repetitive labor, high interface docking cost, inconsistent specifications, and manual errors.
[0003] In order to solve the above problems, some code generators in the industry can automatically generate entity classes or backend skeleton code, and some platforms can generate front-end page fragments. However, these technologies have many shortcomings such as incomplete generation capability, difficulty in flexible customization of templates, large amount of manual modification for front-end and back-end binding, and difficulty in meeting enterprise specifications with generated results. The above shortcomings seriously affect the application development efficiency. SUMMARY
[0004] Therefore, the purpose of the present application is to provide a code generation method and system based on table structure, which can effectively improve the project development efficiency and code quality.
[0005] In a first aspect, the present application provides a code generation method based on table structure, which comprises the following steps: performing table structure analysis on a data table in a preset data source to obtain table structure meta-information; performing field semantic recognition on the table structure meta-information according to a preset rule library to determine front-end control type and back-end validation rules; calling a code template to perform rendering processing according to a preset generation strategy, the table structure meta-information, the front-end control type and the back-end validation rules, and generating original code; performing interface binding of the front-end and the back-end on the original code to generate target code.
[0006] In some embodiments, the table structure analysis on the data table in the preset data source to obtain the table structure meta-information comprises: reading a preset data source; wherein the data source comprises target database metadata or table structure files; perform table structure analysis on the data source to obtain table structure meta-information, wherein the table structure meta-information at least includes a field list, a field type, a default value, whether null, a primary key, a unique constraint, a foreign key relationship, field annotation or display name, enumeration or dictionary mapping.
[0007] In some embodiments, the method further comprises: managing a set of code templates, wherein the code templates at least include Java entity classes, Repository / Mapper interfaces, Service layers, Controller layers, DTOs, unit tests, Vue list pages, form pages, routes, interface service layer calls, and permission annotations; the code templates support placeholder replacement, conditional blocks and loops, fragment reuse, and custom extensions.
[0008] In some embodiments, the rendering processing is performed on the target code template according to the preset generation strategy, the table structure meta-information, the front-end control type, and the back-end verification rule to generate the original code, including: determining a generation strategy, wherein the generation strategy includes single table, parent-child table, CRUD, or complex association; determining a target code template corresponding to the generation strategy from a set of preset code templates; performing field visualization configuration on the table structure meta-information; performing rendering processing on the target code template by taking the front-end control type, the back-end verification rule, and the table structure meta-information after field visualization configuration as a rendering context, and outputting the original code.
[0009] In some embodiments, the field visualization configuration on the table structure meta-information includes: performing field visualization configuration on the table structure meta-information according to a preset field configuration template or through a visualization configuration panel.
[0010] In some embodiments, the interface binding of the original code includes: the original code includes a back-end Java file and a front-end Vue file; generating a front-end API calling layer based on a back-end Controller in the back-end Java file; injecting route information and adding permission meta-information in a route configuration file in the front-end Vue file to generate the target code.
[0011] In some embodiments, the method further comprises: performing static checking and code formatting on the target code and outputting to a specified project path or packaging as a code file.
[0012] In a second aspect, the embodiment of the present application provides a code generation system based on table structure, which comprises the following modules: a table structure analysis module, configured to analyze table structure of a data table in a preset data source to obtain table structure meta information; a field semantic identification module, configured to identify field semantics of the table structure meta information according to a preset rule library to determine a front-end control type and a back-end verification rule; a code generation module, configured to call a code template to perform rendering processing according to a preset generation strategy, the table structure meta information, the front-end control type and the back-end verification rule, and generate original code; an interface binding module, configured to bind interfaces of the front end and the back end for the original code to generate target code.
[0013] In a third aspect, the embodiment of the present application further provides a server, comprising a processor and a storage device; the storage device stores a computer program, and the computer program realizes steps of the code generation method based on table structure mentioned in the first aspect when being run by the processor.
[0014] In a fourth aspect, the embodiment of the present application further provides a readable storage medium, which stores a computer program, and the computer program executes steps of the code generation method based on table structure mentioned in the first aspect when being run by a processor.
[0015] The embodiment of the present application brings at least the following beneficial effects: The present application provides a code generation method, system, server and medium based on table structure, relating to the technical field of computer, which comprises: analyzing table structure of a data table in a preset data source to obtain table structure meta information; identifying field semantics of the table structure meta information according to a preset rule library to determine a front-end control type and a back-end verification rule; calling a code template to perform rendering processing according to a preset generation strategy, the table structure meta information, the front-end control type and the back-end verification rule, and generating original code; binding interfaces of the front end and the back end for the original code to generate target code.
[0016] In the technical solution, firstly, based on table structure analysis and field semantic recognition, intelligent mapping of front-end and back-end code elements is realized, front-end control type and back-end check rules are automatically matched, limitations of traditional code generation which only rely on data types and ignore business semantics are avoided, and the adaptation degree of code and actual business scenarios is greatly improved. Secondly, by generating a strategy and combining table structure meta information, front-end control type and back-end check rules, a code template is called to perform rendering processing, without manually writing repetitive code and configuration logic, development workload and time cost can be significantly reduced, and the generated original code is highly unified in code style and architecture specification, effectively improving the maintainability of the system and the team collaboration efficiency. Finally, through the interface binding of the original code in the front-end and the back-end, the seamless connection of the front-end and the back-end calling link is automatically completed, the interface address, parameter agreement and routing permission configuration are unified, the manual collaboration error of the front-end and the back-end is effectively eliminated, the interface joint debugging problem is reduced, and the generated code is no longer an isolated segment, but an immediately integrable and executable function module. Therefore, the project development efficiency and code quality are effectively improved.
[0017] Other features and advantages of the present application will be set forth in the following description, or will be apparent from the description, or can be learned by practice of the application according to the foregoing techniques.
[0018] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the following preferred embodiments are described in detail below, and the accompanying drawings are described as follows. BRIEF DESCRIPTION OF DRAWINGS
[0019] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the following will briefly introduce the drawings needed to be used in the specific embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and those skilled in the art can also obtain other drawings according to these drawings without creative labor.
[0020] Figure 1 A flowchart of a code generation method based on table structure provided by an embodiment of the present application; Figure 2 A schematic diagram of a code generation process based on table structure provided by an embodiment of the present application; Figure 3 A flowchart of a method for generating original code provided by an embodiment of the present application; Figure 4 A structural schematic diagram of a code generation system based on table structure provided by an embodiment of the present application; Figure 5 A structural schematic diagram of an electronic device provided by an embodiment of the present application.
[0021] Icon: 410-table structure analysis module; 420-field semantic identification module; 430-code generation module; 440-interface binding module; 101-processor; 102-memory; 103-bus; 104-communication interface. DETAILED DESCRIPTION
[0022] In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions of the present application will be described clearly and completely below with reference to the drawings. Obviously, the described embodiments are only some of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0023] In the enterprise-level application development process, some code generation tools and frameworks can be used. For example, tools such as MyBatis Generator, Hibernate Tools, etc. can automatically generate part of the persistence layer code such as entity classes, data mapping files or basic interface definitions according to database tables. In addition, there are also some more integrated code generation platforms or low-code platforms, such as JHipster, which can generate a complete application front-end and back-end skeleton code.
[0024] As some examples, MyBatis Generator, Hibernate Tools can generate entities, mappings and part of DAO (Data Access Object), but the front-end support is weak and the template extensibility is limited. JHipster can generate a complete set of front-end and back-end projects, but it lacks support for fine-grained field mapping of database tables, enterprise customization field conventions and complex check / permission scenarios, and the generated volume is large, which is not convenient for modular deployment according to single tables. Some low-code tools: friendly interface, but strong dependence on closed source or cloud, cannot completely generate according to existing enterprise templates and code specifications, and the readability and maintainability of the generated code are not enough.
[0025] It can be seen that the above-mentioned solutions still have many limitations, resulting in limited improvement of development efficiency and inability to achieve rapid delivery of modules. For example, at least the following problems exist: The front-end and back-end generation is separated or incomplete, and cannot achieve the level of module rapid online of taking table; the template and generation logic cannot be flexibly extended, and the support for field conventions (such as enumeration, foreign key, dictionary complex check) is insufficient; the generated code often needs a lot of manual secondary processing to meet interface contract, permission check, business expansion; cannot automatically complete front-end and back-end interface binding and routing configuration, resulting in limited improvement of development efficiency.
[0026] To improve at least one of the above problems, the embodiment of the present application provides a code generation method, system and electronic equipment based on table structure. The method can automatically generate a complete set of front-end and back-end codes (back-end Java files and front-end Vue files) based on database table structure, realize zero or low manual automation from table structure to executable module, improve development efficiency, reduce interface connection errors, and support template and scalable generation strategy to meet enterprise standards.
[0027] To facilitate the understanding of the present embodiment, first, a code generation method based on table structure disclosed by the present embodiment is introduced in detail. The method is applied to the scene of enterprise-level application development. As shown in Figure 1 The code generation method based on table structure includes the following steps: Step S101, table structure analysis is performed on the data table in the preset data source to obtain table structure meta information.
[0028] In the present embodiment, the table structure analysis module (Schema Parser) can be used to perform table structure analysis on the data table in the preset data source to obtain table structure meta information. The above data source may, for example, include target database metadata or table structure files.
[0029] This step, when implemented, can include: reading a preset data source; wherein the data source includes: target database metadata or table structure files; performing table structure analysis on the data source to obtain table structure meta information; wherein the table structure meta information at least includes: field list, field type, default value, whether null, primary key, unique constraint, foreign key relationship, field annotation or display name, enumeration or dictionary mapping.
[0030] Specifically, in combination with Figure 2 , the target database metadata (such as MySQL, PostgreSQL, Oracle, SQLServer) or the imported table structure file (such as JSON, YAML, SQL DDL) is read by the table structure analysis module; the above data source is analyzed for table structure, and the field list, field type, default value, whether null, primary key, unique constraint, foreign key relationship, field annotation / display name, enumeration / dictionary mapping and many other fields are analyzed. These fields are table structure meta information.
[0031] The present embodiment can provide accurate, rich and structured input for subsequent code generation by adapting to multiple data sources and performing table structure analysis, which can ensure the quality and accuracy of the subsequent generated code.
[0032] In step S102, field semantics of the table structure meta information is identified according to a preset rule base, and a front-end control type and a back-end check rule are determined.
[0033] In the embodiment, the field semantics of the table structure meta information can be identified by a field semantic analyzer according to a preset rule base, and the front-end control type and the back-end check rule are determined.
[0034] In specific embodiments, the field semantic analyzer can identify the field semantics of the table structure meta information based on the preset rule base and information (such as a field name, a field annotation / display name, a field type, etc.) representing the original attributes of the fields in the table structure meta information, and mark one or more semantic tags for each field in the table structure meta information; the semantic tags are, for example, time, mailbox, mobile phone number, amount, status code, picture URL, and rich text. The corresponding front-end control type and back-end check rule are inferred based on the semantic tags of the fields in the table structure meta information.
[0035] The rules included in the rule base can include at least one of the following: a keyword matching rule, an annotation matching rule, and a regular expression verification.
[0036] In example one, the keyword matching rule can be a mapping rule of a keyword and a semantic tag. Based on the keyword matching rule, it is checked whether the field name includes a preset keyword, and the semantic tag of the field is determined according to the semantic tag mapped by the keyword.
[0037] For example, if it is checked that the field name includes email / mail, it is determined that the semantic tag of the field is a mailbox. According to the semantic tag of the field being a mailbox, it is determined that the front-end control type is a front-end mailbox, and it is determined that the back-end check rule is a mailbox check annotation for checking whether the mailbox format is correct: @Email(message="incorrect mailbox format").
[0038] For another example, if it is checked that the field name includes amount / price / money, it is determined that the semantic tag of the field is an amount. According to the semantic tag of the field being an amount, it is determined that the front-end control type is a front-end input box with a currency symbol, and it is determined that the back-end check rule is an amount check annotation for checking whether the input amount format is correct: @DecimalMin(value="0.0", message="amount cannot be negative").
[0039] In example two, the annotation matching rule. Based on the annotation matching rule, the field annotation is subjected to natural language processing, and the semantic tag is determined.
[0040] For example, the field note is a user avatar, and its semantic label is determined as a picture URL through natural language processing. According to the semantic label of the field being a picture URL, the front-end control type is determined as a front-end picture upload component, and the back-end verification rule is determined as a back-end file path or URL verification rule.
[0041] Example three, regular expression verification. For data with strict formats such as email and mobile phone number, regular expressions can be used to verify the example value extracted from the field name or note to increase the confidence of semantic recognition.
[0042] Step S103, according to the preset generation strategy, table structure meta information, front-end control type and back-end verification rule, calling code template to perform rendering processing to generate original code.
[0043] The embodiment first introduces the code template. As for the code template, the method provided in the embodiment can include: The set of code templates is managed; wherein the code templates at least include: Java entity class, Repository / Mapper interface, Service layer, Controller layer, DTO, unit test, Vue list page, form page, route, interface service layer call and permission annotation; the code template supports placeholder replacement, conditional block and loop, fragment reuse and custom extension.
[0044] The embodiment can maintain and manage the set of extensible code templates through the template engine module (Template Engine). The code template supports placeholder replacement, conditional block and loop, fragment reuse and custom extension.
[0045] Among them, the code template is extended and customized according to user operations; the above-mentioned user operations include adding operation, modifying operation and adding custom field. That is, a new code template is established through the adding operation; the current existing code template is modified through the modifying operation; a new field and its field attribute are established through the adding custom field operation. Through the above-mentioned user operation, the flexible configuration of code development such as coding specification, log, verification strategy and AOP (Aspect-Oriented Programming, Aspect-Oriented Programming) in the actual application development process is met.
[0046] In combination with Figure 2 and Figure 3 , the embodiment can generate original code by calling the code template to perform rendering processing according to the preset generation strategy, table structure meta information, front-end control type and back-end verification rule through the generator (Generator Or chestrator); the implementation process of the embodiment can refer to the following steps.
[0047] In step S301, a generation strategy is determined, and the generation strategy includes a single table, a parent-child table, CRUD, or a complex association.
[0048] In this embodiment, the generator can determine a generation strategy according to user requirements or a table structure association relationship. The generation strategy is, for example, a single table, a parent-child table, CRUD, or a complex association.
[0049] In step S302, a target code template corresponding to the generation strategy is determined from a set of preset code templates.
[0050] In this embodiment, the target code template corresponding to the generation strategy is filtered from a set of code templates maintained by the template engine module according to the generation strategy.
[0051] For example, it can be determined whether the generation strategy is a multi-table association. If it is not a multi-table association, that is, the generation strategy is a single table, a complete set of code templates is filtered from the set of code templates as the target code template: Java entity class, Repository / Mapper interface, Service layer, Controller layer, DTO, unit test, Vue list page, form page, routing, interface service layer call, and permission annotation.
[0052] If it is a multi-table association, for example, the generation strategy is a parent-child table, a complete set of code templates is filtered from the set of code templates, and a specific code template for processing a one-to-many relationship is also selected; the filtered complete set of code templates and the specific code template are collectively used as the target code template. For example, in the Form template of the parent table, an editable table template of the child table is embedded; in the back-end DTO, a structure containing a list of child objects is generated.
[0053] In step S303, field visualization configuration is performed on the table structure meta information.
[0054] In one possible embodiment, the field visualization configuration can be performed on the table structure meta information according to a preset field configuration template or through a visualization configuration panel, thereby specifying how each field in the table structure meta information should be visually represented in the finally generated user interaction interface.
[0055] The field configuration template is a pre-set visualization mapping rule for each field, and each field in the table structure meta information is automatically visually configured based on the field configuration template. The visualization panel can provide a UI interface to the user to visually configure each field in the table structure meta information through the user's configuration operation on the field.
[0056] The field visualization configuration of the table structure meta information can specifically include: determining the front-end display (such as column width, formatting), search conditions (such as fuzzy search, accurate search, and search range), form control type (such as input box, drop-down, date interval, picture upload), and verification rules (such as mandatory or optional, length, regular) according to a preset field configuration template.
[0057] The field visualization configuration of the table structure meta information can specifically include: in response to a configuration operation of a user on a UI interface, selecting a table according to the configuration operation, configuring display and hiding of fields, specifying which fields are used for searching, sorting, paging, whether to be used as a table primary key, and whether to generate import and export functions.
[0058] In step S304, the table structure meta information after the front-end control type, the back-end verification rule, and the field visualization configuration is used as a rendering context to perform rendering processing on the target code template, and an original code is output. The original code includes a back-end Java file and a front-end Vue file.
[0059] In this embodiment, the generator calls the template engine module, uses the table structure meta information after the front-end control type, the back-end verification rule, and the field visualization configuration as a rendering context, performs rendering processing such as placeholder replacement and conditional logic triggering on the target code template, and outputs the rendered original code. The original code is, for example, a Vue form with a mobile phone input box and a DTO class with email verification.
[0060] Then, the embodiment can perform file path organization, naming specification, code formatting, version annotation, and the like on the rendered original code to ensure that the finally output original code meets the enterprise specification and can be directly used in the subsequent development process.
[0061] The original code described above includes a back-end Java file and a front-end Vue file. The back-end Java file includes entities, Mapper / Repository, Service, Controller, DTO, exception handling, and unit test stubs. The front-end Vue file includes List.vue, Form.vue, service.js, route.js, and i18n text.
[0062] Regarding the generator in this embodiment, in actual application, the generator can be integrated into a target project in a script or containerized manner and compiled and started. Alternatively, a Module plug-in is provided for a user to manually introduce the generator into the target project according to actual needs.
[0063] In step S104, the original code is subjected to interface binding of the front end and the back end, and a target code is generated.
[0064] In this embodiment, the original code includes a backend Java file and a frontend Vue file; the backend Java file includes a backend controller, and the frontend Vue file includes a route configuration file (i.e., route.js). Based on the backend controller in the backend Java file, a frontend API call layer is generated; wherein the API call layer contains frontend request functions. Route information and permission metadata are injected into the route configuration file in the frontend Vue file to generate the target code.
[0065] This embodiment generates a Controller on the backend using an API Binder, and simultaneously generates a frontend API call layer based on the generated backend Controller. Specifically, it parses the interface information in the backend Controller, such as extracting the mapping annotations, request methods, and parameter structures of each method; it generates a corresponding JavaScript / TypeScript file (usually service.js or api.js) for each public method in the backend Controller, defining the corresponding frontend request function; this frontend request function uses an HTTP library such as Axios or Fetch. This creates the corresponding frontend API call layer.
[0066] This embodiment generates the front-end API call layer based on the back-end Controller in the back-end Java file, which enables automatic alignment of the front-end and back-end interface contracts.
[0067] Furthermore, this embodiment uses an interface binder to inject routing information and add permission metadata into the route.js configuration file in the front-end Vue file, thereby achieving uniformity in address and parameter conventions.
[0068] Specifically, the route configuration file is bound to the route path, such as / customer / list corresponding to CustomerList.vue and / customer / form corresponding to CustomerForm.vue, thereby injecting route information.
[0069] Add a meta field to the route configuration file, such as meta: { title: 'Customer Management', permission:'customer:read'}, to associate the page title with the backend interface permission identifier, thereby adding permission meta information.
[0070] According to the above embodiment, it can be ensured that the API interface generated by the backend can be accurately, efficiently and normatively called by the frontend, and the routing and permission configuration of the frontend application can be automatically completed. Specifically, the frontend Vue file obtains the backend data by calling the frontend request function of the API calling layer, the routing information ensures that the page is accessible, and the permission meta information supports the frontend permission control, thereby realizing the automatic closed loop from the table structure to the executable module.
[0071] On the basis of the above embodiment, the table structure-based code generation method provided by the present disclosure can further include: performing static checking and code formatting on the target code, and outputting to a specified project path or packing as a code file, such as a zip format code file.
[0072] On the basis of the above embodiment, a possible example in an application scenario is provided, which is shown as follows.
[0073] In the first step, the input data is that a user selects a table customer in a database crm_db, and a table definition example is as follows: id INT PK AUTO_INCREMENT Note: customer ID name VARCHAR(100) Note: customer name mobile VARCHAR(20) Note: contact phone number email VARCHAR(100) Note: email status TINYINT Note: status (0-disabled 1-enabled) created_at DATETIME Note: creation time In the second step, the following processing steps are performed: Schema Parser obtains the field metadata of customer.
[0074] Field Analyzer identifies: mobile is a mobile phone number (application of mobile phone number verification); email is an email address; status is identified as an enumeration / dictionary (generate a drop-down); created_at is identified as a time range search (generate a time interval control in the frontend).
[0075] Generate configuration: by default, id, name, mobile, status, and created_at are displayed in the list; Name supports fuzzy search; status supports drop-down filtering; created_at supports time range filtering; in the form, name, email, and mobile are mandatory.
[0076] Template Engine renders the backend templates to generate Customer.java (entity), CustomerMapper.xml or CustomerRepository, CustomerService, CustomerController (contains list, get, save, update, delete interfaces); Also generates the frontend CustomerList.vue, CustomerForm.vue, customerService.js (encapsulates API calls), customerRoute.js. Interface contract example: GET / api / customer / list?page=1&size=20&name=xx&status=1.
[0077] API Binder injects meta information in the frontend route: meta: { title: 'Customer Management', permission: 'customer:read'}, and uses uniform error handling and Toast prompts in the generated Service.
[0078] Outputs the code and formats it, generating a zip package or directly writing to the target project module directory.
[0079] Step 3, generate example code snippets (pseudo code) as follows: Backend Controller (pseudo): @RestController @RequestMapping(" / api / customer") public class CustomerController { @GetMapping(" / list") public PageResult <customerdto>list(CustomerQuery query) {...} @GetMapping(" / {id}") public CustomerDTO get(@PathVariable Long id) {...} @PostMapping(" / save") public Result save(@RequestBody CustomerDTO dto) {...} @PostMapping(" / update") public Result update(@RequestBody CustomerDTO dto) {...} @PostMapping(" / delete") public Result delete(@RequestBody List <long>ids) {...} } Front-end call (pseudo) : / / customerService.js export function getCustomerList(params) { return request({ url: ' / api / customer / list', method: 'get', params}); } export function saveCustomer(data) { return request({ url: ' / api / customer / save', method: 'post', data}); } In summary, the code generation method based on table structure provided by the embodiment of the disclosure comprises: performing table structure analysis on a data table in a preset data source to obtain table structure meta information; performing field semantic identification on the table structure meta information according to a preset rule library to determine a front-end control type and a back-end verification rule; calling a code template to perform rendering processing according to a preset generation strategy, the table structure meta information, the front-end control type and the back-end verification rule, to generate original code; and performing front-end and back-end interface binding on the original code to generate target code.
[0080] In the technical solution, firstly, based on table structure analysis and field semantic identification, intelligent mapping of front-end and back-end code elements is realized, front-end control types and back-end verification rules are automatically matched, the limitation of traditional code generation that only relies on data types and ignores business semantics is avoided, and the adaptation degree of code to actual business scenarios is greatly improved. Secondly, by generating a strategy and combining table structure meta information, front-end control types and back-end verification rules, a code template is called to perform rendering processing, without the need for manual writing of repetitive code and configuration logic, which can significantly reduce development workload and time cost, and ensure that the code style and architecture specification of the generated original code are highly unified, effectively improving the maintainability of the system and the team collaboration efficiency. Finally, by performing front-end and back-end interface binding on the original code, seamless connection of the front-end and back-end calling links is automatically completed, unified interface addresses, parameter conventions and routing permission configurations are achieved, manual collaboration errors in front-end and back-end connection are effectively eliminated, interface joint debugging problems are reduced, and the generated code is no longer an isolated fragment, but an immediately integrable and executable function module. Therefore, the scheme effectively improves project development efficiency and code quality.
[0081] More specifically, the present scheme can improve development efficiency: the single table CRUD module is shortened from several days to several minutes; (2) reduce the interface docking cost: the front and back end generation simultaneously follow the same contract, reduce manual adjustment and joint debugging time; (3) improve code consistency and maintainability: driven by templates, generated code conforms to uniform style and specifications; (4) support high customization: templates and extension points support enterprise-level customization, adapt to different business scenarios; (5) reduce human error and repetitive labor, improve online quality.
[0082] Corresponding to the above method embodiment, the present embodiment provides a table structure-based code generation system, as shown in Figure 4 The system comprises the following modules: The table structure analysis module 410 is configured to analyze the table structure of the data table in the preset data source to obtain table structure meta-information. The field semantic recognition module 420 is configured to recognize the field semantics of the table structure meta-information according to a preset rule library to determine the front-end control type and the back-end verification rule. The code generation module 430 is configured to call a code template to perform rendering processing according to a preset generation strategy, the table structure meta-information, the front-end control type and the back-end verification rule, and generate original code. The interface binding module 440 is configured to bind the original code to the front end and the back end to generate target code.
[0083] The table structure-based code generation system provided by the present embodiment first realizes intelligent mapping of front-end and back-end code elements based on table structure analysis and field semantic recognition, automatically matches front-end control types and back-end verification rules, avoids the limitations of traditional code generation which only relies on data types and ignores business semantics, and greatly improves the adaptability of code to actual business scenarios. Secondly, by generating a strategy and combining table structure meta-information, front-end control types and back-end verification rules, a code template is called to perform rendering processing, without the need for manual writing of repetitive code and configuration logic, which can significantly reduce development workload and time cost, and ensure that the generated original code has a high degree of uniformity in code style and architecture specifications, effectively improving the maintainability and team collaboration efficiency of the system. Finally, by binding the original code to the front end and the back end, the seamless docking of the front-end and back-end calling links is automatically completed, the interface address, parameter agreement and routing permission configuration are unified, the manual collaboration error in front-end and back-end docking is effectively eliminated, the interface joint debugging problem is reduced, and the generated code is no longer an isolated fragment, but an immediately integrable and executable functional module. Therefore, the present scheme effectively improves project development efficiency and code quality.
[0084] The code generation system based on the table structure provided in this embodiment has the same technical features as the code generation method based on the table structure provided in the above embodiment, and can also solve the same technical problems and achieve the same technical effects. For brief description, the part not mentioned in the embodiment can refer to the corresponding content in the code generation method based on the table structure provided in the above embodiment.
[0085] This embodiment also provides an electronic device, a structural diagram of which is shown in Figure 5 The device includes a processor 101 and a memory 102; the memory 102 is configured to store one or more computer instructions, and the one or more computer instructions are executed by the processor to implement the code generation method based on the table structure.
[0086] Figure 5 The electronic device shown in the figure also includes a bus 103 and a communication interface 104, and the processor 101, the communication interface 104 and the memory 102 are connected through the bus 103.
[0087] The memory 102 can include a high-speed random access memory (RAM), and can also include a non-volatile memory, for example, at least one disk memory. The bus 103 can be an ISA bus, a PCI bus or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, Figure 5 Only one bidirectional arrow is used to represent the bus in the figure, but it does not mean that there is only one bus or only one type of bus.
[0088] The communication interface 104 is configured to connect with at least one user terminal and other network units through a network interface, and send the encapsulated IPv4 packet or IPv4 packet to the user terminal through the network interface.
[0089] The processor 101 can be an integrated circuit chip having a processing capability of signals. In the implementation process, each step of the above method can be completed by the integrated logic circuit of hardware in the processor 101 or the instruction in the form of software. The processor 101 described above can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. Each method, step and logic block diagram disclosed in the embodiments of the present disclosure can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in combination with the embodiments of the present disclosure can be directly embodied as a hardware code processor for execution, or a combination of hardware and software modules in the code processor for execution. The software module can be located in a random access memory, a flash memory, a read only memory, a programmable read only memory or an electrically erasable programmable memory, a register or other mature storage medium in the art. The storage medium is located in the memory 102, and the processor 101 reads the information in the memory 102 and combines the hardware to complete the steps of the method of the above embodiments.
[0090] The embodiment of the present application further provides a readable storage medium, and the readable storage medium stores a computer program. When the computer program is run by a processor, the steps of the code generation method based on the table structure of the above embodiment are executed.
[0091] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented by other ways. The above-described device embodiments are only schematic, for example, the division of the units is only a logical function division, and other division manners can be used in actual implementation, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some communication interfaces, devices or units, and can be electrical, mechanical or other forms.
[0092] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, i.e. may be located in one place, or may be distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0093] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0094] If the functions are realized in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer readable storage medium executable by a processor. Based on this understanding, the technical solutions of the present application or the part of the present application that essentially contributes to the prior art or the part of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes instructions for making a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in each embodiment of the present application. The foregoing storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk, and various program code storage media.
[0095] Finally, it should be noted that: the above-described embodiments are only specific embodiments of the present application, used to illustrate the technical solutions of the present application, and not to limit them, the protection scope of the present application is not limited thereto, although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand: any skilled person in the art within the technical range disclosed by the present application, they can still modify or easily think of changes to the technical solutions recorded in the foregoing embodiments, or make equivalent replacement to part of the technical features; and these modifications, changes or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and all should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.< / long> < / customerdto>
Claims
1. A code generation method based on table structure, characterized in that, The method includes the following steps: The table structure of the data table in the preset data source is parsed to obtain the table structure metadata; Based on a preset rule base, the table structure metadata is used to identify the semantics of the fields, thereby determining the front-end control type and back-end validation rules. Based on the preset generation strategy, the table structure metadata, the front-end control type, and the back-end validation rules, the code template is invoked to perform rendering processing and generate the original code; The original code is then bound to front-end and back-end interfaces to generate target code.
2. The code generation method based on table structure according to claim 1, characterized in that, The step of parsing the table structure of the data table in the preset data source to obtain table structure metadata includes: Read a preset data source; wherein, the data source includes: target database metadata or table structure file; The data source is parsed to obtain table structure metadata; wherein, the table structure metadata includes at least: field list, field type, default value, whether it is nullable, primary key, unique constraint, foreign key relationship, field comments or display name, enumeration or dictionary mapping.
3. The code generation method based on table structure according to claim 1, characterized in that, The method further includes: The code template collection is managed; the code template includes at least: Java entity classes, Repository / Mapper interfaces, Service layer, Controller layer, DTO, unit tests, Vue list page, form page, routes, interface service layer calls, and permission annotations; the code template supports placeholder replacement, conditional blocks and loops, fragment reuse, and custom extensions.
4. The code generation method based on table structure according to claim 1, characterized in that, The step of generating original code by calling a code template to perform rendering processing based on a preset generation strategy, the table structure metadata, the front-end control type, and the back-end validation rules includes: Determine the generation strategy, which includes: single table, parent-child table, CRUD, or complex relationships; From a set of preset code templates, determine the target code template corresponding to the generation strategy; Configure the fields of the table structure metadata for visualization; Using the front-end control type, the back-end validation rules, and the table structure metadata after field visualization configuration as the rendering context, the target code template is rendered and the original code is output.
5. The code generation method based on table structure according to claim 4, characterized in that, The configuration of field visualization for table structure metadata includes: Configure the table structure metadata fields visually using a preset field configuration template or through a visual configuration panel.
6. The code generation method based on table structure according to claim 1, characterized in that, The step of binding the original code to front-end and back-end interfaces to generate target code includes: The original code includes: backend Java files and frontend Vue files; Based on the backend Controller in the backend Java file, generate the frontend API call layer; Inject routing information and add permission metadata into the routing configuration file in the front-end Vue file to generate target code.
7. The code generation method based on table structure according to claim 1, characterized in that, The method further includes: Perform static analysis and code formatting on the target code, and output the results to a specified project path or package them into a code file.
8. A code generation system based on a table structure, characterized in that, The system includes the following modules: The table structure parsing module is used to parse the table structure of data tables in a preset data source to obtain table structure metadata. The field semantic recognition module is used to recognize the field semantics of the table structure meta-information according to a preset rule base, and to determine the front-end control type and back-end validation rules. The code generation module is used to call the code template to perform rendering processing and generate the original code according to the preset generation strategy, the table structure meta information, the front-end control type and the back-end validation rules; The interface binding module is used to bind the original code to the front-end and back-end interfaces to generate the target code.
9. A server, characterized in that, include: Processors and storage devices; The storage device stores a computer program, which, when run by the processor, implements the steps of the table-based code generation method according to any one of claims 1 to 7.
10. A readable storage medium, characterized in that, The readable storage medium stores a computer program that, when executed by a processor, performs the steps of the table-based code generation method according to any one of claims 1 to 7.