[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN113176877B - Entity class generation method, device and storage medium - Google Patents

Entity class generation method, device and storage medium Download PDF

Info

Publication number
CN113176877B
CN113176877B CN202110585710.5A CN202110585710A CN113176877B CN 113176877 B CN113176877 B CN 113176877B CN 202110585710 A CN202110585710 A CN 202110585710A CN 113176877 B CN113176877 B CN 113176877B
Authority
CN
China
Prior art keywords
data file
configuration information
file
entity class
entity
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.)
Active
Application number
CN202110585710.5A
Other languages
Chinese (zh)
Other versions
CN113176877A (en
Inventor
梁树成
刘江
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Grela Technology Co ltd
Original Assignee
Beijing Grela 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 Grela Technology Co ltd filed Critical Beijing Grela Technology Co ltd
Priority to CN202110585710.5A priority Critical patent/CN113176877B/en
Publication of CN113176877A publication Critical patent/CN113176877A/en
Application granted granted Critical
Publication of CN113176877B publication Critical patent/CN113176877B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/289Phrasal analysis, e.g. finite state techniques or chunking
    • G06F40/295Named entity recognition

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Computational Linguistics (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computing Systems (AREA)
  • Artificial Intelligence (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present disclosure relates to an entity class generation method, apparatus, and storage medium, the method comprising: when the file script file is executed, configuration information of a first data file and configuration information of a second data file are respectively obtained, wherein file types of the first data file and the second data file are different; comparing the configuration information of the first data file with the configuration information of the second data file, and extracting the configuration information meeting preset conditions; and generating entity classes corresponding to the first data file and the second data file based on the configuration information meeting preset conditions. According to the method and the device, the configuration information of the first data file and the second data file is obtained, the configuration information meeting the preset conditions is extracted, and the entity class is automatically generated based on the configuration information meeting the preset conditions, so that the process of manually developing codes can be simplified, the development efficiency is improved, the complexity of back-end development is reduced, redundant fields are reduced, and the generation efficiency of the entity class and errors in the entity class are improved.

Description

Entity class generation method, device and storage medium
Technical Field
The disclosure relates to the technical field of computers, and in particular relates to a method and a device for generating entity class and a storage medium.
Background
The main purpose of the entity class is to store data and provide access to such data. Typically, each configuration table needs to correspond to an entity class. The existing configuration tables usually need to be written manually, each configuration table needs to be written, in addition, a large number of fields exist in the same configuration table, the data types of the fields are different, and errors are easy to generate.
Disclosure of Invention
The disclosure aims to provide a method, a device and a storage medium for generating entity class, which can solve the technical problems that a configuration table in the prior art needs to be written manually, time and labor are wasted, and a large number of fields exist in the configuration table and errors are easy to generate.
According to one aspect of the present disclosure, there is provided a method for generating an entity class, including:
when a file script file is executed, configuration information of a first data file and configuration information of a second data file are respectively obtained, wherein file types of the first data file and the second data file are different;
Comparing the configuration information of the first data file with the configuration information of the second data file, and extracting the configuration information meeting preset conditions;
And generating entity classes corresponding to the first data file and the second data file based on the configuration information meeting preset conditions.
In some embodiments, the first data file is a json file and the second data file is an Excel file.
In some embodiments, comparing the configuration information of the first data file with the configuration information of the second data file, extracting the configuration information satisfying the preset condition includes:
comparing the field name of the first data file with the field name of the second data file, and extracting the same fields in the first data file and the second data file.
In some embodiments, generating the entity class corresponding to the first data file and the second data file based on the configuration information meeting the preset condition includes:
Constructing a mapping relation between the entity class and the field based on the extracted field;
And generating the corresponding entity class based on the mapping relation.
In some embodiments, the method further comprises:
And generating an access object according to the generated entity class.
In some embodiments, after generating the access object according to the generated entity class, the method further comprises:
Assigning values to the corresponding attributes in the access object based on the attribute information in the entity class to obtain the attribute value of the access object;
And extracting related attribute values in the access object, and executing related operations according to the attribute values.
According to one of the schemes of the present disclosure, there is also provided an entity class generating apparatus, including:
the file management system comprises an acquisition module, a file management module and a file management module, wherein the acquisition module is configured to acquire configuration information of a first data file and configuration information of a second data file respectively when a file script file is executed, and file types of the first data file and the second data file are different;
The extraction module is configured to compare the configuration information of the first data file with the configuration information of the second data file and extract the configuration information meeting the preset condition;
And the generating module is configured to generate entity classes corresponding to the first data file and the second data file based on the configuration information meeting preset conditions.
In some embodiments, the extraction module is specifically configured to:
comparing the field name of the first data file with the field name of the second data file, and extracting the same fields in the first data file and the second data file.
In some embodiments, the generating module is specifically configured to:
Constructing a mapping relation between the entity class and the field based on the extracted field;
And generating the corresponding entity class based on the mapping relation.
According to one aspect of the present disclosure, there is also provided a computer-readable storage medium having stored thereon computer-executable instructions that, when executed by a processor, implement the above-described entity class generation method.
According to the entity class generation method, the entity class generation device and the storage medium, the configuration information of the first data file and the second data file is obtained, the configuration information meeting the preset conditions is extracted, the entity class is automatically generated based on the configuration information meeting the preset conditions, the process of manually developing codes can be simplified, the development efficiency is improved, and the complexity of back-end development is reduced; meanwhile, redundant fields can be reduced, the generation efficiency of entity classes is improved, and errors in the entity classes are reduced.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure, as claimed.
Drawings
In the drawings, which are not necessarily to scale, like reference numerals in different views may designate like components. Like reference numerals with letter suffixes or like reference numerals with different letter suffixes may represent different instances of similar components. The accompanying drawings generally illustrate various embodiments by way of example, and not by way of limitation, and are used in conjunction with the description and claims to explain the disclosed embodiments.
FIG. 1 is a flow diagram of a method for generating entity classes according to an embodiment of the disclosure;
FIG. 2 illustrates an architectural diagram of an entity class generation apparatus of one embodiment of the present disclosure.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more apparent, the technical solutions of the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present disclosure. It will be apparent that the described embodiments are some, but not all, of the embodiments of the present disclosure. All other embodiments, which can be made by one of ordinary skill in the art without the need for inventive faculty, are within the scope of the present disclosure, based on the described embodiments of the present disclosure.
Unless defined otherwise, technical or scientific terms used in this disclosure should be given the ordinary meaning as understood by one of ordinary skill in the art to which this disclosure belongs. The word "comprising" or "comprises", and the like, means that elements or items preceding the word are included in the element or item listed after the word and equivalents thereof, but does not exclude other elements or items.
In order to keep the following description of the embodiments of the present disclosure clear and concise, the present disclosure omits detailed description of known functions and known components.
As one of the schemes, as shown in fig. 1, an embodiment of the present disclosure provides a method for generating an entity class, including:
s101: and when the file script file is executed, respectively acquiring configuration information of a first data file and configuration information of a second data file, wherein file types of the first data file and the second data file are different.
Specifically, the server may acquire a first data file and a second data file when executing the script file, where in this embodiment, the first data file is a json file and the second data file is an Excel file. The first data file is a json format file, the stored data is lightweight, the data is easy to read and write, meanwhile, the data is easy to analyze and generate by a machine, and the transmission efficiency can be effectively improved.
The configuration information includes: table name, field type, field length, whether the field is null, field annotation, etc.
In some embodiments, prior to executing the script file, the method further comprises: and constructing a script execution environment by using the script language.
The script language comprises NodeJS, python, php languages, and in the embodiment, nodeJS is used for development, and a development environment is convenient to build.
S102: and comparing the configuration information of the first data file with the configuration information of the second data file, and extracting the configuration information meeting the preset condition.
In the embodiment of the present disclosure, S102 specifically includes:
comparing the field name of the first data file with the field name of the second data file, and extracting the same fields in the first data file and the second data file.
In one embodiment, the first data file is a.json and the second data file is a.xls.
The content in json is { "a":1, "b":2, "c":3}, wherein "a", "b", "c" represent field names, respectively; 1.2, 3 are the values of the fields corresponding to the field names, respectively.
The contents in a.xls are shown in table 1, where the first row in a.xls represents a field name. The second row represents the field type of the field and the third row represents the value of the field owned by a different field.
TABLE 1
a b c d
int int int int
1 2 3 4
After comparing the data of the a.json file with the data of the a.xls file, the same field names and the corresponding field information (e.g., field types, field values, etc.) thereof are extracted, i.e., the "a", "b", "c" and "1", "2", "3" are extracted. When the field type is not limited by the a.json file, since the field type is limited by a.xls, the extracted field type may be determined as "int".
In this embodiment, when extracting field information, for the same field, the overall field information is extracted as much as possible, so as to ensure the accuracy of entity class generation.
In other embodiments, the configuration information meeting the preset condition may be configuration information having a certain specific association relationship in the configuration information of the first data file and the configuration information of the second data file, so that the specific configuration information meeting the preset condition may be extracted from the first data file and the second data file.
S103: and generating entity classes corresponding to the first data file and the second data file based on the configuration information meeting preset conditions.
The step S103 specifically includes the following steps:
s1031: constructing a mapping relation between the entity class and the field based on the extracted field;
S1032: and generating the corresponding entity class based on the mapping relation.
After the same fields in the first data file and the second data file are extracted, determining the entity type to be generated and attribute information corresponding to the entity type based on the extracted fields, so as to construct a mapping relationship between the entity type and the fields, and further generate the entity type meeting the mapping relationship.
The generated entity class includes attributes and methods, where the attributes correspond to fields in the data file. Methods mainly include getter and setter methods, getter represents a value, and setter represents a value. The generated class attributes may include List and the like. For example, the attribute names in the entity class may be determined based on the extracted field names.
In this embodiment, the generated Entity class (Entity) includes, but is not limited to, java class, where the file type of the java class is java.
The method also comprises the following steps of: the location of the generated entity class is determined. For example, an entity class deposit path (a path for generating a java file) may be determined based on the json file path and/or the Excel file path.
The results of generating entity classes using the above a.json and a.xls files are as follows:
Where @ Getter is used for value and @ ToString is used for annotation.
As described above, in the generated entity class, only the fields contained in both files are generated, so that the number of fields in the entity class can be effectively reduced, and when the data file is read to the memory, the occupied space of the file memory is reduced, and the access efficiency is improved. In the generated entity class, the type of the attribute is usually private.
According to the entity class generation method provided by the embodiment of the disclosure, the configuration information of the first data file and the second data file is obtained, the configuration information meeting the preset conditions is extracted, and the entity class is automatically generated based on the configuration information meeting the preset conditions, so that the flow of manually developing codes can be simplified, the development efficiency is improved, and the complexity of back-end development is reduced; meanwhile, redundant fields can be reduced, the generation efficiency of entity classes is improved, and errors in the entity classes are reduced. In addition, the entity class generated in the embodiment only maps data, so that the accuracy of entity class generation can be effectively improved.
After the entity class is generated, the entity class can be packaged and encapsulated to determine a package name (package). The same class name can exist under different package names, for example, when two aenty.java files exist, the package names can be distinguished into different entity classes as long as the package names are different.
In some embodiments, after generating the entity class corresponding to the first data file and the second data file, the method further includes:
S104: and generating an access object according to the generated entity class.
The access object is an entity object contained in the entity class, in this embodiment, attribute information of the entity class is converted into Map set for storage (Map is used for making a Map) through a Java reflection mechanism, that is, for any one class, all attributes and methods of the class can be known. Therefore, the entity class can be traversed according to the Java reflection mechanism, the attribute of the entity class is obtained, and then the access object is generated according to the attribute of the entity class, namely, various attribute information in the Java class is mapped into individual Java objects, and the operation can be performed. Any method and attribute of any object can be invoked; and can change its properties.
The specific generation mode of the access object can be expressed as:
Wherein the @ Resource tag is responsible for injection.
In some embodiments, after generating the access object according to the generated entity class, the method further comprises:
s1051: assigning values to the corresponding attributes in the access object based on the attribute information in the entity class to obtain the attribute value of the access object;
s1052: and extracting related attribute values in the access object, and executing related operations according to the attribute values.
In some embodiments, the method further comprises:
and when the back-end server is started, automatically loading the generated configuration file of the entity class.
The configuration file of the entity class generated by automatic loading can realize automatic loading of the content of the configuration file, and the programming efficiency is improved.
As one of the schemes, as shown in fig. 2, an embodiment of the present disclosure provides an entity class generating apparatus, including:
An obtaining module 201, configured to obtain configuration information of a first data file and a second data file when a file script is executed, where file types of the first data file and the second data file are different;
an extraction module 202 configured to compare the configuration information of the first data file with the configuration information of the second data file, and extract configuration information satisfying a preset condition;
And the generating module 203 is configured to generate entity classes corresponding to the first data file and the second data file based on the configuration information meeting the preset condition.
As a specific implementation, the extraction module 202 of this embodiment may be further configured to:
comparing the field name of the first data file with the field name of the second data file, and extracting the same fields in the first data file and the second data file.
As a specific implementation manner, the generating module 203 of this embodiment may be specifically configured to:
Constructing a mapping relation between the entity class and the field based on the extracted field;
And generating the corresponding entity class based on the mapping relation.
As a specific implementation manner, the generating module 203 of this embodiment may be further configured to: and generating an access object according to the generated entity class.
As a specific implementation manner, the entity class generating apparatus of this embodiment may further include an operation module configured to:
Assigning the fields in the entity class to the corresponding attributes in the access object;
And extracting related attribute values in the access object, and executing related operations according to the attribute values.
The entity class generating device provided in the embodiment of the present disclosure corresponds to the entity class generating method in the above embodiment, and any optional item in the embodiment of the entity class generating method is also applicable to the embodiment, which is not described in detail herein.
The embodiment of the disclosure also provides a computer readable storage medium, on which computer executable instructions are stored, the computer executable instructions, when executed by a processor, mainly implement the entity class generation method, at least including:
when a file script file is executed, configuration information of a first data file and configuration information of a second data file are respectively obtained, wherein file types of the first data file and the second data file are different;
Comparing the configuration information of the first data file with the configuration information of the second data file, and extracting the configuration information meeting preset conditions;
And generating entity classes corresponding to the first data file and the second data file based on the configuration information meeting preset conditions.
In some embodiments, a processor executing computer-executable instructions can be a processing device including more than one general purpose processing device, such as a microprocessor, central Processing Unit (CPU), graphics Processing Unit (GPU), or the like. More specifically, the processor may be a Complex Instruction Set Computing (CISC) microprocessor, a Reduced Instruction Set Computing (RISC) microprocessor, a Very Long Instruction Word (VLIW) microprocessor, a processor running other instruction sets, or a processor running a combination of instruction sets. The processor may also be one or more special purpose processing devices such as an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), a system on a chip (SoC), or the like.
The computer readable storage medium described above may be a memory such as read-only memory (ROM), random-access memory (RAM), phase-change random-access memory (PRAM), static random-access memory (SRAM), dynamic random-access memory (DRAM), electrically erasable programmable read-only memory (EEPROM), other types of random-access memory (RAM), flash memory disk or other forms of flash memory, cache, registers, static memory, compact disc read-only memory (CD-ROM), digital Versatile Disc (DVD) or other optical storage, magnetic cassettes or other magnetic storage devices, or any other possible non-transitory medium which can be used to store information or instructions that can be accessed by a computer device, and the like.
The computer-executable instructions of embodiments of the present disclosure may be organized into one or more computer-executable components or modules. Aspects of the disclosure may be implemented with any number and combination of such components or modules. For example, aspects of the present disclosure are not limited to the specific computer-executable instructions or the specific components or modules illustrated in the figures and described herein. Other embodiments may include different computer-executable instructions or components having more or less functionality than illustrated and described herein.
The above embodiments are merely exemplary embodiments of the present disclosure, which are not intended to limit the present disclosure, the scope of which is defined by the claims. Various modifications and equivalent arrangements of parts may be made by those skilled in the art, which modifications and equivalents are intended to be within the spirit and scope of the present disclosure.

Claims (6)

1. A method of entity class generation, comprising:
when a file script file is executed, configuration information of a first data file and configuration information of a second data file are respectively obtained, wherein file types of the first data file and the second data file are different;
Comparing the configuration information of the first data file with the configuration information of the second data file, and extracting the configuration information meeting preset conditions;
Generating entity classes corresponding to the first data file and the second data file based on the configuration information meeting preset conditions;
wherein comparing the configuration information of the first data file with the configuration information of the second data file, extracting the configuration information meeting the preset condition includes:
Comparing the field name of the first data file with the field name of the second data file, and extracting the same fields in the first data file and the second data file;
based on the configuration information meeting the preset condition, generating entity classes corresponding to the first data file and the second data file, including:
Constructing a mapping relation between the entity class and the field based on the extracted field;
And generating the corresponding entity class based on the mapping relation.
2. The method of claim 1, wherein the first data file is a json file and the second data file is an Excel file.
3. The method of claim 1, wherein the method further comprises:
And generating an access object according to the generated entity class.
4. A method according to claim 3, wherein after generating an access object from the generated entity class, the method further comprises:
Assigning values to the corresponding attributes in the access object based on the attribute information in the entity class to obtain the attribute value of the access object;
And extracting related attribute values in the access object, and executing related operations according to the attribute values.
5. An entity class generation apparatus, comprising:
the file management system comprises an acquisition module, a file management module and a file management module, wherein the acquisition module is configured to acquire configuration information of a first data file and configuration information of a second data file respectively when a file script file is executed, and file types of the first data file and the second data file are different;
The extraction module is configured to compare the configuration information of the first data file with the configuration information of the second data file and extract the configuration information meeting the preset condition;
The generation module is configured to generate entity classes corresponding to the first data file and the second data file based on the configuration information meeting preset conditions;
wherein, the extraction module is specifically configured to:
Comparing the field name of the first data file with the field name of the second data file, and extracting the same fields in the first data file and the second data file;
The generation module is specifically configured to:
Constructing a mapping relation between the entity class and the field based on the extracted field;
And generating the corresponding entity class based on the mapping relation.
6. A computer-readable storage medium having stored thereon computer-executable instructions that, when executed by a processor, implement:
The entity class generation method according to any one of claims 1 to 4.
CN202110585710.5A 2021-05-27 2021-05-27 Entity class generation method, device and storage medium Active CN113176877B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110585710.5A CN113176877B (en) 2021-05-27 2021-05-27 Entity class generation method, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110585710.5A CN113176877B (en) 2021-05-27 2021-05-27 Entity class generation method, device and storage medium

Publications (2)

Publication Number Publication Date
CN113176877A CN113176877A (en) 2021-07-27
CN113176877B true CN113176877B (en) 2024-08-13

Family

ID=76927567

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110585710.5A Active CN113176877B (en) 2021-05-27 2021-05-27 Entity class generation method, device and storage medium

Country Status (1)

Country Link
CN (1) CN113176877B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114895912A (en) * 2022-06-07 2022-08-12 康键信息技术(深圳)有限公司 Method, device, equipment and medium for converting entity class object under coding architecture

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108241720A (en) * 2016-12-27 2018-07-03 北京京东尚科信息技术有限公司 Data processing method and data processing equipment

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107704479B (en) * 2017-02-08 2020-06-30 深圳壹账通智能科技有限公司 File generation method and device
CN110851129A (en) * 2019-11-13 2020-02-28 深圳市泰洲科技有限公司 Automatic generation method of software system code of data management class

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108241720A (en) * 2016-12-27 2018-07-03 北京京东尚科信息技术有限公司 Data processing method and data processing equipment

Also Published As

Publication number Publication date
CN113176877A (en) 2021-07-27

Similar Documents

Publication Publication Date Title
US9424009B2 (en) Handling pointers in program code in a system that supports multiple address spaces
US8418134B2 (en) Method for efficiently managing property types and constraints in a prototype based dynamic programming language
US11650754B2 (en) Data accessing method, device, and storage medium
CN113791768B (en) Code generation method and device, storage medium and terminal
US11995059B2 (en) Database index and database query processing method, apparatus, and device
US20110197178A1 (en) Architecture, system, and method for providing hover help support for c++ application source code
CN108241720B (en) Data processing method, device and computer readable storage medium
US20230315416A1 (en) Code translation method and apparatus, and device
CN115599386A (en) Code generation method, device, equipment and storage medium
CN111475150B (en) Cross-language binding method, device, equipment and storage medium
CN112187713B (en) Message conversion method, device, computer equipment and storage medium
CN113434734A (en) Method, device, equipment and storage medium for generating file and reading file
CN113176877B (en) Entity class generation method, device and storage medium
CN105867886B (en) Method and device for writing table
US9836305B1 (en) Systems and methods for task parallelization
CN114816772B (en) Debugging method, debugging system and computing device for application running based on compatible layer
CN116414689A (en) Interface parameter verification method and system based on reflection mechanism
CN104915352A (en) Method and device for verifying processed data accuracy under MapReduce environment
CN115858183B (en) Inter-process joint analysis method, device and equipment for asynchronous parallel I/O request
US12117996B2 (en) Schema-free static query template
CN117033497B (en) Method for updating and reading data on data lake and related equipment
CN117075912B (en) Method for program language conversion, compiling method and related equipment
CN112445784B (en) Text structuring method, equipment and system
CN117874002A (en) Method and system for heterogeneous data migration
CN116257673A (en) Data query method, device, equipment and storage medium based on elastic search

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant