Data retrieval method, device, electronic device and storage medium
By detecting and utilizing the list header information of the target file or database, determining and using predefined list headers and attribute names, reading and storing data to reusable components, the cumbersome and complex problems of data import and export in the prior art are solved, and efficient and convenient data import and export are achieved.
Patent Information
- Application Number
- CN202110036733.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-12
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2041-01-12
AI Technical Summary
In the prior art, when importing or exporting data from Office software to a database, code identification headers need to be written through the SDK of Apache POI, resulting in high code coupling and poor universality, and re-written codes when the table header fields change.
By detecting the list header information of the target file or database, determine the target table header file, and determine the target list header and its corresponding index information and attribute name based on the predefined list header and attribute name. Using this information, the row data in the target file is read and stored in a reusable component, and the data set is generated and stored in a database.
It realizes the rapid and convenient import and export of data to the database without changing the program code, reducing the degree of code coupling and improving the universality and efficiency of data import and export.
Smart Images

Figure CN113760894B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a data retrieval method, device, electronic device, and storage medium. Background Art
[0002] In the actual application process, there is a need to import data from office software into the database, or export data from the database to office software. The import and export processes need to be operated through the Apache POI SDK.
[0003] When implementing the technical solution based on the above method, the inventor found the following problems:
[0004] When importing or exporting data based on the Apache POI SDK, it is necessary to identify the table header based on the fields written in the code and then obtain the corresponding data. However, when the fields in the table header change, such as the field value changes or the number of fields changes, it is necessary to rewrite the corresponding code and then identify the corresponding table header data based on the updated code. At this time, there are problems such as high code coupling and poor versatility. Summary of the invention
[0005] The present invention provides a data retrieval method, device, electronic device and storage medium to achieve the technical effect of quickly and conveniently importing or exporting data to a database without changing program codes.
[0006] In a first aspect, an embodiment of the present invention provides a data caching method, the method comprising:
[0007] When a trigger operation of storing data in a target file into a database is detected, a target header file is determined from a file set including header files according to column header information of the target file; the header file includes a predefined column header and an attribute name corresponding to the predefined column header;
[0008] Determine the target column header to be read according to the column header information and the predefined column header in the target table header file, and determine the column index information corresponding to the target column header in the target file and the target attribute name corresponding to the column index information;
[0009] For the row data in the target file, read the current row data in sequence according to the index information, and store the column data in the current row data and the target attribute name in a reusable component in correspondence;
[0010] Based on the reusable components corresponding to each row of data, the data sets are generated and stored in the database.
[0011] In a second aspect, an embodiment of the present invention further provides a data retrieval method, the method comprising:
[0012] When a trigger operation of exporting target data in a database to a target file is detected, a target header file is generated according to the target list header triggered by the user; the target header file includes the triggered target list header, index information of the target list header, and an attribute name corresponding to the target list header;
[0013] Generate a document list header of the target document according to the attribute name corresponding to the target list header and the index information;
[0014] The target data filled in the attribute information of each reusable component are sequentially written under the document list header of the target document according to the index information; the attribute information of the reusable component includes the attribute name and the data corresponding to the attribute name.
[0015] In a third aspect, an embodiment of the present invention further provides a data cache device, the device comprising:
[0016] A target header file determination module is used to determine a target header file from a file set including header files according to column header information of the target file when a trigger operation of storing data in the target file into a database is detected; the header file includes a predefined column header and an attribute name corresponding to the predefined column header;
[0017] A target column header information generating module, used to determine the target column header to be read according to the column header information and the predefined column header in the target column header file, and determine the column index information corresponding to the target column header in the target file and the target attribute name corresponding to the column index information;
[0018] An attribute information determination module, for sequentially reading the current row data according to the index information for the row data in the target file, and storing the column data in the current row data and the target attribute name in a reusable component in correspondence;
[0019] The reusable component generation module is used to generate data sets based on the reusable components corresponding to each row of data and store them in the database.
[0020] In a fourth aspect, an embodiment of the present invention further provides a data retrieval device, the device comprising:
[0021] A target header file generation module is used to generate a target header file according to a target list header triggered by a user when a trigger operation of exporting target data in a database to a target file is detected; the target header file includes a triggered target list header, index information of the target list header, and an attribute name corresponding to the target list header;
[0022] A document list header generation module, used to generate a document list header of the target document according to the attribute name corresponding to the target list header and the index information;
[0023] The data writing module is used to write the target data filled in the attribute information of each reusable component into the document list header of the target document in sequence according to the index information; the attribute information of the reusable component includes the attribute name and the data corresponding to the attribute name.
[0024] In a fifth aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:
[0025] one or more processors;
[0026] a storage device for storing one or more programs,
[0027] When the one or more programs are executed by the one or more processors, the one or more processors implement the data caching method and / or data retrieval method as described in any one of the embodiments of the present invention.
[0028] In a fourth aspect, an embodiment of the present invention further provides a storage medium comprising computer executable instructions, which, when executed by a computer processor, are used to execute a data caching method and / or a data retrieval method as described in any one of the embodiments of the present invention.
[0029] The technical solution of the embodiment of the present invention determines the target header file from a file set including the header file according to the list header information of the target file when a trigger operation for storing the data in the target file into the database is detected, and determines the target list header according to the list header information and the predefined list header in the target header file. At the same time, the index information of the target list header in the target file and the target attribute name corresponding to the index information are determined. After determining the above information, each row data in the target file can be read in turn, and the row data can be written into a reusable component of the current row data, and the column data in the row data corresponding to the target attribute name in the reusable component. This solves the technical problem in the prior art that corresponding program code needs to be written when importing data into the database, and there is a cumbersome and complicated technical problem of data importing, and achieves the technical effect of conveniently and efficiently importing data into the database. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the following briefly introduces the drawings required to describe the embodiments. Obviously, the drawings introduced are only drawings of a part of the embodiments to be described in the present invention, rather than all the drawings. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0031] Figure 1 A schematic diagram of a data caching method flow chart provided in Embodiment 1 of the present invention;
[0032] Figure 2 A schematic diagram of a data caching method flow chart provided in Embodiment 2 of the present invention;
[0033] Figure 3 A schematic diagram of a data retrieval method flow provided in Embodiment 3 of the present invention;
[0034] Figure 4 A schematic diagram of a data retrieval method provided in Embodiment 4 of the present invention;
[0035] Figure 5 A schematic diagram of a data retrieval and / or caching method provided in Embodiment 5 of the present invention;
[0036] Figure 6 A schematic diagram of the structure of a data cache device provided in Embodiment 6 of the present invention;
[0037] Figure 7 A schematic diagram of the structure of a data retrieval device provided in Embodiment 7 of the present invention;
[0038] Figure 8 This is a schematic diagram of the structure of an electronic device provided in Embodiment 8 of the present invention. DETAILED DESCRIPTION
[0039] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0040] Embodiment 1
[0041] Figure 1 A flow chart of a data caching method provided in Embodiment 1 of the present invention is provided. This embodiment is applicable to the case where a target file, such as data in an Excel file, is imported into a database. The method can be executed by a data caching device, which can be implemented in the form of software and / or hardware. The hardware can be an electronic device. Optionally, the electronic device is a mobile terminal or a PC, etc.
[0042] Before introducing the technical solution of this embodiment, an exemplary application scenario is first described. When the data in the uploaded Excel or the data in the Excel file in the disk can be imported into the database or other storage space, the method provided by this embodiment can be used to read each row of data in Excel in turn, and write the row data into the reusable component, and then store the reusable component in the database, thereby achieving the technical effect of importing the data in the target file into the database.
[0043] like Figure 1 The method of this embodiment includes:
[0044] S110. When a trigger operation for storing data in a target file into a database is detected, a target header file is determined from a file set including header files according to column header information of the target file; the header file includes a predefined column header and an attribute name corresponding to the predefined column header.
[0045] Among them, if it is necessary to read the data in file A, or to write the data in file A into the database, file A can be used as the target file, that is, the file to which the data to be written into the database belongs is used as the target file. The column header information is the column field in the target file. In layman's terms, the column header information is the field in the first row and column cell in the target file. For example, if the target file is an excel file, and the column header of the file includes: item category, item price, etc., then the item category and item price, etc. can be used as the column header information. The header files corresponding to different business types include at least one, and the specific content in the header file is generated according to the predefined column header information. The predefined column header information is determined according to the fields concerned by different business types. For example, the fields concerned by business type A are field A, field B and field C, and the header file is generated based on the above fields; the fields concerned by business type B are field B, field C, and field E, and the header file corresponding to business type B can be generated based on the above fields. In order to convert the above fields into corresponding header files, a reusable component JavaBean can be created in advance, and a custom annotation @ExcelResources can be added to the attribute information of the reusable component JavaBean. The attribute information of the annotation includes fields and the order of fields. Correspondingly, the header file is a header file generated after processing the reusable component with the annotation. That is, the header file is a file including predefined column headers and predefined column header attribute names generated after processing the JavaBean object. The file collection includes multiple elements, each of which can be a header file. The target header file is a file that matches the column header information of the target file.
[0046] Specifically, when it is detected that the user triggers an operation to store the data in the target file into the database, or triggers an operation to store the data of a file on the disk into the database, the list header information of the target file can be obtained, and based on the list header information, a target header file that matches the target file can be determined from multiple header files stored in the file collection.
[0047] In this embodiment, determining the target header file from a file set including header files based on the list header information of the target file includes: determining the target header file from the file set based on the business type corresponding to the target file and the list header information.
[0048] It should be noted that a file collection can store multiple header files, and each business type can correspond to one or more header files, and the specific number can be set by the user according to actual needs. Of course, in the actual application process, all the fields required by a certain business type can be determined, and the corresponding header files can be generated according to all the fields and stored in the file collection.
[0049] Specifically, when uploading a target file or reading a target file from a disk, an interface for uploading the target file or an interface for reading the target file can be determined, and the business type of the target file can be determined according to the interface. According to the business type, at least one header file to be determined corresponding to it can be determined from the file set. Further, according to the column header information in the target file, the target header file can be determined from the at least one header file to be determined.
[0050] In this embodiment, the target header file is determined from the file set according to the business type corresponding to the target file and the column header information, including: determining at least one to-be-determined target header file from the file set according to the business type of the target file; extracting the column header information in the target file based on a data reading tool, and determining a target header file including the column header information or consistent with the column header information from the at least one to-be-determined target header file based on the data reading tool.
[0051] The target header file to be determined is a header file that matches the business type of the target file. The data reading tool can be the SDK of POI, and POI provides an API for the java program to read and write data in the Microsoft Office format document. Based on the data reading tool, the column header information in the target file can be read, and at the same time, the attribute name information in the target header file to be determined can be read. According to the column header information and the attribute name information, the corresponding target column header file can be determined. The header file includes predefined column headers and the attribute names of the column headers. Based on the attribute names, it can be determined which column headers will be read and the corresponding data.
[0052] Specifically, according to the business type of the target file, at least one target header file matching the business type can be determined from the file set. At the same time, based on the data reading tool, the target list header information in the target file and the attribute name information in each target header file to be determined can be read. According to the target list header information and the attribute name information, the target header file to be selected that includes the target list header information or is completely the same as the target list header information can be determined. If the number of target list header files to be selected includes multiple, the target header files to be selected can be displayed on the display interface in the form of a pop-up window or a web page for user selection. The user can trigger the target header file to be selected on the display interface, and use the target header file to be selected that is finally triggered as the target header file.
[0053] S120. Determine a target column header to be read according to the column header information and a predefined column header in the target table header file, and determine column index information corresponding to the target column header in the target file and a target attribute name corresponding to the column index information.
[0054] The target header file is generated by adding a custom annotation @ExcelResources to the property information of the pre-created reusable component JavaBean. The annotation can specify properties, including the predefined column header and the order of the predefined column header. After the property information of the reusable component JavaBean is processed by the reflection mechanism, a java object ExcelHeader can be generated, and ExcelHeader is the header file. The header file includes the predefined column header and the attribute name filedName of the predefined column header. The column header information in the target file may be the same as the predefined column header, and the same column header can be used as the target column header. The index information can be the column information of the target column header in the target file. For example, if the target column header is field A and field A is in the third column in the target file, the index information of field A can be 3. After determining the target column header information, the attribute name of the target column header can be determined from the target header file, so that when creating a reusable component to store each row of data, the column data and the attribute name in the row data can be stored correspondingly. The index information is used as the key, and the index information corresponds to the column header. The attribute name of the column header can be used as the value corresponding to the key.
[0055] Specifically, based on the data reading tool, the column header information in the target file is read, and at the same time, the predefined column header in the target header file is read, the same column header information is used as the target column header, and further, the specific column number of the target column header in the target file and the attribute name of the target column header in the target header file are determined, the specific column number is used as the index information of the target file, and the target attribute name of the column header corresponding to the index information is determined.
[0056] In this embodiment, the target list header information is determined based on the list header information and the predefined list header in the target table header file, and the index information of the target list header information and the attribute name corresponding to the index information are determined, including: when the list header information is consistent with the predetermined list header, the list header information is used as the target list header information; the column value of the target list header in the target file is determined, and the column value is used as the index information; the attribute name of the target list header information is retrieved, and a corresponding relationship between the index information and the attribute name is established, so that when reading data, the read data can be stored under the corresponding attribute name based on the index information.
[0057] It should be noted that in order to read the data in the target file, it is necessary to determine which column header information in the target file is included in the header file, and then read out the data corresponding to the corresponding column header information in the target file.
[0058] Specifically, when it is detected that the list header information is the same as the predefined list header, the same list header can be used as the target list header, and the column value of the target list header in the target file is determined, that is, in which column of the target list header in the target file. This column value can be used as index information. Further, in order to store the data corresponding to the target list header in the database, the target attribute name of the target list header can be determined, so that when reading each row of data, the corresponding data can be stored according to the index information and the corresponding attribute name.
[0059] Exemplarily, the fields corresponding to the list header information are field A, field B, field C, and field D in order. The predetermined list header includes field A and field D. Based on the data reading tool, the target list header can be determined to be field A and field D. At the same time, it can be determined that the column values of field A and field D in the target file are 1 and 4. In order to unify the subsequent data processing, the column values can be counted from 0, the column value of field A is 0, and the column value of field D can be 3. After determining the column values, the attribute name of the target list header can be determined according to the target file. Put the same list header into the Map collection (key = column value, value = filedName of the target list header in ExcelHeader, that is, the attribute name of JavaBean).
[0060] In this embodiment, the advantage of such a setting is that when reading each row of data in the file, the column data in the row data can be read based on the index information obtained above, and after creating a reusable component for storing the row data, the read column data and the attribute name corresponding to the index information are written into the reusable component.
[0061] S130. For the row data in the target file, read the current row data in sequence according to the index information, and store the column data in the current row data and the target attribute name in a corresponding manner in a reusable component.
[0062] After obtaining the column data, column data index information and corresponding attribute names written into the database based on S110 and S120, each column data in the row data can be read in sequence based on the above relationship, and the column data can be stored according to the corresponding attribute name.
[0063] It should be noted that this method can be used to read data for each row of data in the target file. This embodiment takes reading one row of data as an example.
[0064] The reusable component may be used as a carrier for storing each row of data, that is, each column of data in the row of data may be stored in the reusable component according to the corresponding attribute name.
[0065] Specifically, for each row of data, a JavaBean instance object can be generated, that is, each row of data can generate a JavaBean instance object, and the corresponding data is not written into the JavaBean instance object at this time. The current row of data is read in sequence according to the index information, that is, according to the index information, it can be determined which specific column data in the current row of data to read and the attribute name corresponding to the column data, and the column data corresponding to the index information and the corresponding target attribute name can be written into the JavaBean instance object.
[0066] In this embodiment, the current row data is read in sequence according to the index information, and the column data in the current row data and the target attribute name are stored in the attribute information of the reusable component in correspondence with each other, including: for each column data in the row data, the current column data is read according to the index information, and the target attribute name corresponding to the index information is determined; based on the column data and the target attribute name, the attribute information of the reusable component corresponding to the current row data is determined.
[0067] Specifically, each row of data includes multiple columns of data, including data stored in the database and data not written into the database. Therefore, the column data to be written into the database in the current row of data can be read according to the index information, and the corresponding target attribute name can be determined according to the index information. When reading the column data corresponding to the index information, the corresponding target attribute name can be retrieved, and the column data and the target attribute name can be written into the attribute information of the JavaBean instance object accordingly. This method achieves the effect of writing the row data into the JavaBean instance object.
[0068] S140: Generate a data set based on the reusable components corresponding to each row of data and merge and store them in a database.
[0069] Based on S130, the instance object (reusable component) of the JavaBean corresponding to each row of data in the target file can be obtained, and a data set (LIST) can be generated based on each reusable component, and the data set can be persisted in the database.
[0070] That is, a data set may be generated according to the reusable components corresponding to each row of data in the target file, and the data set may be stored in a database and / or a file to be cached, wherein the file to be cached may also be a file in the database.
[0071] The technical solution of the embodiment of the present invention determines the target header file from a file set including the header file according to the list header information of the target file when a trigger operation for storing the data in the target file into the database is detected, and determines the target list header according to the list header information and the predefined list header in the target header file. At the same time, the index information of the target list header in the target file and the target attribute name corresponding to the index information are determined. After determining the above information, each row data in the target file can be read in turn, and the row data can be written into a reusable component of the current row data, and the column data in the row data corresponding to the target attribute name in the reusable component. This solves the technical problem in the prior art that corresponding program code needs to be written when importing data into the database, and there is a cumbersome and complicated technical problem of data importing, and achieves the technical effect of conveniently and efficiently importing data into the database.
[0072] Embodiment 2
[0073] Figure 2 A flow chart of a data caching method provided in the second embodiment of the present invention is provided. Based on the above embodiment, a reusable component can be created in advance and a custom annotation can be added to the reusable component. Furthermore, the reusable component with the annotation is converted into a header file, and the header file is stored in a file collection. The specific implementation method can refer to the technical solution of this embodiment. Among them, the technical terms that are the same as or corresponding to the above embodiment are not repeated here.
[0074] like Figure 2 As shown, the method includes:
[0075] S210. Create at least one predefined reusable component, and add an annotation to the attribute information of the at least one predefined reusable component; the annotation attribute information of the annotation includes a predefined column header.
[0076] Among them, the predefined reusable component can be a pre-created JavaBean object. In the actual application process, the Class of JavaBean can be established according to actual needs, and the specific business object type can define the Class type of JavaBean. There can be multiple predefined reusable components, and the specific number can be set according to actual needs. Optionally, one business type corresponds to one reusable component, or corresponds to multiple reusable components. The annotation information can be a custom annotation @ExcelResources. The annotation @ExcelResources can be used on the JavaBean attribute. The attributes can be specified in the annotation. The attributes can include column headers and the order corresponding to the column headers. For example, the attributes in the annotation can be "title (predefined column header), order (the order corresponding to the predetermined column header)". Corresponding annotations can be added to the attribute information of each reusable component. The specific value of the predefined column header in the annotation can be determined according to the field concerned by the corresponding business type.
[0077] Specifically, at least one reusable component JavaBean corresponding to each business type is created. For each reusable component, an annotation @ExcelResources is added to the property information of the current reusable component, and the annotation information may include predefined column headers and order information of the predefined column headers.
[0078] S220. For each predefined reusable component, identify annotation information in the predefined reusable component according to a reflection mechanism, and generate a header file according to the annotation information, wherein the header file includes a predefined column header and an attribute name corresponding to the predefined column header.
[0079] Among them, the reusable components after adding annotations can be obtained, and the attribute information of the predefined reusable components can be identified based on the reflection mechanism, and the annotation information in the attribute information can be extracted, that is, which annotations are marked on the reusable components, and optionally, what is the predefined column header in the annotation. At the same time, based on the reflection mechanism, the attribute information of each predefined reusable component can be processed to generate the ExcelHeader of the Java object, that is, the header file. The header file can include the predefined column header in the annotation, that is, the column header title specified when the annotation is customized, the order of the column header, and the JavaBean attribute name filedName, that is, the attribute name of the predetermined column header. The header file ExcelHeader generated above can be stored in the file collection (List).
[0080] In the actual application process, after the predefined reusable component is created, the reusable component with annotations can be processed into a header file using the reflection mechanism and stored in a file collection. It can also be that when the operation of storing the data in the target file in the database is detected, the target reusable component of the target file is determined, and then it is processed into a header file and stored in the file collection, and finally the header file is searched from the file collection. The advantage of adopting the first implementation method is that the reflection mechanism can be used in advance to generate an ExcelHeader file from the reusable component (JavaBean) with annotations. When the target file is uploaded, the corresponding header file can be searched from the file collection, avoiding the need to use the reflection mechanism to convert the corresponding predefined reusable component into the corresponding header file each time it is uploaded, thereby achieving the technical effect of avoiding reducing resource consumption; the advantage of the second implementation method is that it can avoid the problem of redundant storage resources caused by a large number of header files stored in the file collection.
[0081] S230. When a trigger operation for storing the data in the target file into the database is detected, a target header file is determined from a file set including header files according to the column header information of the target file; the header file includes a predefined column header and an attribute name corresponding to the predefined column header.
[0082] Specifically, when a trigger operation is detected to store the data in the target file into the database, the SDK of the data reading tool POI can be used to read the first line of the target file and obtain the fields in the first line, that is, the column header information in the target file. According to the column header information in the target file, the target header file ExcelHeader is determined from the file collection headers, that is, the target header file that matches the column header information.
[0083] S240. Determine the target column header to be read according to the column header information and the predefined column header in the target table header file, and determine the column index information corresponding to the target column header in the target file and the target attribute name corresponding to the column index information.
[0084] Specifically, based on the SDK traversing the predefined list headers in the target header file ExcelHeader and the list header information in the target file, the same target list header information can be put into a Map. The key in the Map is the index of the column where the cell of the target list header in the target file is located, and the value = the value of the filedName attribute of the target list header in ExcelHeader, that is, the attribute name annotated in the JavaBean.
[0085] S250. For the row data in the target file, read the current row data in sequence according to the index information, and store the column data in the current row data and the target attribute name in a corresponding manner in a reusable component.
[0086] Specifically, the target file may be an Excel file. For each row of data in the Excel file, a data reading tool may be used to read the Excel row data. Before reading the row data, an instance object of a JavaBean for each row of data may be generated based on a reflection mechanism, that is, an object carrier for storing the row data may be created. JavaBean is a reusable component.
[0087] For each row of data, when reading each column of data in the current row of data, the index value of the current column of data can be determined. If the index value is the same as the key value in the Map, reflection can be used to assign the column data corresponding to the index value to the value (attribute name) corresponding to the key, and then write the corresponding column data and the corresponding attribute name of the index value to the pre-created JavaBean instance object. Repeat this step to obtain the instance object of the JavaBean corresponding to each row of data. The instance object obtained at this time is the data after the data is written.
[0088] S260: Generate a data set based on the reusable components corresponding to each row of data and merge and store it in a database.
[0089] It should be noted that S250 may be repeatedly executed to read each row of data in the target file, and store the row of data in the corresponding JavaBean instance object.
[0090] Specifically, after obtaining the reusable components corresponding to each row of data, a data set may be generated and stored in a database so that corresponding data can be retrieved from the database later.
[0091] The technical solution of the embodiment of the present invention determines the target header file from a file set including the header file according to the list header information of the target file when a trigger operation for storing the data in the target file into the database is detected, and determines the target list header according to the list header information and the predefined list header in the target header file. At the same time, the index information of the target list header in the target file and the target attribute name corresponding to the index information are determined. After determining the above information, each row data in the target file can be read in turn, and the row data can be written into a reusable component of the current row data, and the column data in the row data corresponding to the target attribute name in the reusable component. This solves the technical problem in the prior art that corresponding program code needs to be written when importing data into the database, and there is a cumbersome and complicated technical problem of data importing, and achieves the technical effect of conveniently and efficiently importing data into the database.
[0092] Embodiment 3
[0093] Figure 3 The present invention provides a flowchart of a data retrieval method provided in the third embodiment of the present invention. This embodiment can be applied to exporting data stored in a database or a file library to a target file, such as an Excel file. The method can be executed by a data reading device, which can be implemented in the form of software and / or hardware. The hardware can be an electronic device, and the electronic device can be a mobile terminal or a PC, etc.
[0094] Before introducing the technical solution of this embodiment, an exemplary application scenario is first described. When importing data stored in a database into an office file, the method disclosed in this embodiment can be used to export the target data in the database to the corresponding document, thereby achieving the technical effect of exporting the data in the database to the corresponding file without modifying the program code.
[0095] like Figure 3 The method of this embodiment includes:
[0096] S310. When a trigger operation to export target data in a database to a target file is detected, a target header file is generated according to the target list header triggered by the user; the target header file includes the triggered target list header, index information of the target list header and the attribute name corresponding to the target list header.
[0097] The data stored in the database may be data imported in a manner based on the prior art, for example, data imported into the database based on written program code, in which case the data is mainly stored in rows; or each row of data may be stored in the attribute information of the reusable component, that is, the reusable component javabean is used as a carrier for storing data. The data that the user currently needs to export from the database may be used as the target data. The column headers corresponding to each business type may be displayed on the same page. When the user exports data, the column header information on the page may be triggered, and the triggered column header may be used as the target column header. After the target column header is selected, the target column header may be used as the title annotated in the attribute information of the reusable component, that is, the column header. After adding the annotation, it may be processed based on the reflection mechanism to generate a target header file. The header file includes the triggered target column header, the index information of the target column header, and the attribute name of the target column header. The index information is the order of the target column header, and the attribute name corresponds to the triggered target column header.
[0098] Specifically, when it is detected that the user triggers the export of target data, a column header can be selected on the column header display page, and the selected column header is used as the target column header. A target column header file can be generated according to the target column header triggered by the user.
[0099] It should be noted that if the exported target data is stored based on JavaBean, the JavaBean instance object corresponding to the target data can be directly obtained. If the exported target data is stored based on program code, a header file can be generated according to the triggered target list header.
[0100] Specifically, obtain the target list header triggered by the user, create a rebuildable component and add annotations to the attribute information, including the target list header. Based on the reflection mechanism, the attributes of the custom annotations in the JavaBean can be determined to generate the Java object ExcelHeader. ExcelHeader includes the target list header triggered by the user, the order of the target list headers, and the JavaBean attribute name filedName.
[0101] S320: Generate a document list header of the target document according to the attribute name corresponding to the target list header and the index information.
[0102] The index information is used to characterize the order of the target column headers. Based on the index information in the ExcelHeader, the column order information of the target column headers in the target file can be determined. By traversing the target column headers in the ExcelHeader, the first row of fields of the target file, i.e., the column header information of the target file, can be generated.
[0103] In this embodiment, before generating the column header information in the target file, the method further includes: calling a data reading tool to generate a document display style of the target document to display the imported data based on the document display style.
[0104] The data retrieval tool may be the SDK of POI, based on which the target column header in the reusable component can be read, and the target document display style headerStyle can be generated according to the target column header. The display style may be the font of the column header in the target file, the color of the cell to which the column header belongs, etc. It can be understood that the target file is an Excel file, and the value of the column header is filled by the title attribute value of the ExcelHeader object, and an Excel file including the column header can be obtained.
[0105] Specifically, the POI SDK is called to generate the style headerStyle of the list header in the target file. Based on the style, the corresponding data can be filled in the list header, that is, the specific content of the list header, such as name, age and other information.
[0106] S330. Write each target data filled in the attribute information of each reusable component into the document list header of the target document in sequence according to the index information; the attribute information of the reusable component includes an attribute name and data corresponding to the attribute name.
[0107] On the basis of the above technical solution, after the column header information in the target file is generated, the target data can be imported into the corresponding column header information in the target file, that is, the data is stored corresponding to the target column header.
[0108] Before importing data into the target file, the target data can be stored in the form of rows in the database. The row data can be first stored in the reusable component, and then the data is extracted from the reusable component and imported into the target file. The reason is that when reading data directly, the column header information of the data in the target file is uncertain, so the data cannot be correctly written into the target file.
[0109] In this embodiment, before writing each target data filled in the attribute information of each reusable component into the document list header of the target document in sequence according to the index information, it also includes: for each row of data in the target data, creating a reusable component to be used, and obtaining the corresponding attribute name according to the index information, and using the attribute name as the attribute information of the reusable component to be used; for each row of data, reading the current row of data in sequence according to the index information, and storing the column data in the current row of data in correspondence with the corresponding attribute name to obtain a reusable component.
[0110] It can be understood that after finding the target data from the database or file, the target data can be transferred, that is, a javabean instantiation object is created to store the target data. At this time, no data is stored in the instantiation object. The current row data can be read according to the index information, and the column data and attribute names in the current row data that are the same as the index information are stored in the reusable component accordingly, thereby achieving the technical effect of reading the reusable component to read the data into the target file.
[0111] The technical solution of the embodiment of the present invention temporarily stores the target data in a reusable component when exporting the target data from the database, processes the reusable component based on a reflection mechanism, and then writes the data stored in the reusable component into the target file in sequence. This achieves the technical effect of exporting data from the database to the target document without modifying the corresponding program code, thereby improving the efficiency of data export.
[0112] Embodiment 4
[0113] As an alternative embodiment of the above embodiment, Figure 4A schematic diagram of a data reading method provided in the fourth embodiment of the present invention. Based on the above embodiments, the data stored in the database can be stored in the form of reusable components; or the data can be imported into the database in a code-based manner, in which case the stored data is mainly stored in the form of row data. When exporting data from a database or file to an Excel file, its specific implementation method can also refer to the technical solution of this embodiment. Among them, the technical terms that are the same as or corresponding to the above embodiments are not repeated here.
[0114] like Figure 4 As shown, the method includes: when it is detected that the target data is extracted from the database or file, the queried data can be transferred to the list collection. If the data stored in the list collection is stored in Javabean as a carrier, that is, the list collection includes a Javabean instance object collection of the target data, the Javabean instance object collection can be traversed to generate the first row in the excel file. Based on the reflection mechanism, the Javabean instance object is converted into a header file, such as excelheader, and the number of excelheaders is the same as the number of Javabean instance objects. By traversing the data corresponding to the attribute name in the excelheader, each column data in the current row can be generated, and after reading the data corresponding to the attribute name in each excelheader in turn, an excel file including the target data can be obtained. If the storage of the target data is not based on JavaBean as a carrier, a JavaBean object can be created, and the list header triggered in the list header selection page can be added as an annotation to the attribute information of the JavaBean object. Based on the reflection mechanism, the attributes of the annotation added in the JavaBean object are reflected to obtain the excelheader. The title annotation in Excelheader is the triggered column header, the order annotation is the index of title, and the filedname annotation is on which attribute, that is, the data corresponding to which title needs to be read. For each row of data, a JavaBean object can be created, and the attribute name can be written into the created JavaBean object based on excelheader, and the column data in the row data can be stored corresponding to the attribute name. Then, the JavaBean object of each row of data is processed based on the reflection mechanism to obtain the excelheader instance object collection of the target data. Call the SDK to read the excelheader instance object collection, generate the row data of the first row in the excel file, that is, the column header information, read the data corresponding to the attribute name in each excelheader in turn, and obtain the excel file including the target data, thus achieving the technical effect of exporting the target data from the database to the target file.
[0115] The technical solution of the embodiment of the present invention temporarily stores the target data in a reusable component when exporting the target data from the database, processes the reusable component based on a reflection mechanism, and then writes the data stored in the reusable component into the target file in sequence. This achieves the technical effect of exporting data from the database to the target document without modifying the corresponding program code, thereby improving the efficiency of data export.
[0116] Embodiment 5
[0117] As an alternative embodiment of the above embodiment, Figure 5 A schematic diagram of a data caching or retrieving method provided by an embodiment of the present invention is shown in FIG. Technical terms that are the same as or corresponding to those in the above embodiment are not described in detail here.
[0118] like Figure 5As shown, the method includes: the document headers corresponding to different business types can be the same or different, the column headers of different business types can be predefined, the column headers of different documents can be set, and the column header can be used as a custom annotation @ExcelResources. After determining the column header, a reusable component can be created, that is, the data to be operated is encapsulated through a JavaBean object, and the corresponding annotation @ExcelResources is added to the attribute information of the reusable component JavaBean object, the annotation includes the corresponding column header title, the title value is the field of the first row in the table, and order indicates the order of the column header in the uploaded file; at the same time, a reusable component JavaBean object can be created. Add the custom annotation @ExcelResources to the attribute information of the JavaBean object to specify the attributes title and order, that is, the specific value of the title can be determined according to actual needs, that is, what the field is specifically. Based on the reflection mechanism, that is, reflection in Java, the attributes title and order set by the annotation on the JavaBean attribute are obtained. If the application is used to store data in a file into a database, the Excel column header to be imported is associated with the corresponding JavaBean attribute, and a Map collection is generated based on the same column header. The key in the Map collection represents the number of columns in the Excel file with the same column header, and the value represents the attribute name corresponding to the column header. Based on the Map collection, each row of data in the Excel file can be traversed, and the row data can be stored in the JavaBean object corresponding to the row. That is, after the Map collection is established, a JavaBean instantiation object for each row of data is created. At this time, no data is stored in the instantiation object. Each row of data can be read based on the Map collection, and the row data can be stored in the corresponding JavaBean object. After the Excel row data is traversed, the same number of JavaBean objects as the number of rows can be obtained. All JavaBean objects are persisted in the database.
[0119] If the data in the database is exported to an excel file, the JavaBean object carrying the data can be associated with the excel column header, and the column header information of the excel file can be generated according to the order of the annotation settings in the JavaBean object. At the same time, the style of the column header can be set based on the data reading tool. Based on this style, the JavaBean data set can be traversed to generate each row of data corresponding to excel, and then an excel file is generated or responded to the browser for download by the client. If the data in the database is not stored based on the JavaBean instantiated object, a JavaBean object corresponding to each row of data can be created, and the JavaBean object can be used as a carrier for storing data, and then the data can be obtained from the JavaBean object into the target file. The specific implementation method can be referred to Example 4, which realizes the technical effect of exporting data to the target file without modifying the corresponding program code.
[0120] The technical solution of the embodiment of the present invention determines the target header file from a file set including the header file according to the list header information of the target file when a trigger operation for storing the data in the target file into the database is detected, and determines the target list header according to the list header information and the predefined list header in the target header file. At the same time, the index information of the target list header in the target file and the target attribute name corresponding to the index information are determined. After determining the above information, each row data in the target file can be read in turn, and the row data can be written into a reusable component of the current row data, and the column data in the row data corresponding to the target attribute name in the reusable component. This solves the technical problem in the prior art that corresponding program code needs to be written when importing data into the database, and there is a cumbersome and complicated technical problem of data importing, and achieves the technical effect of conveniently and efficiently importing data into the database.
[0121] Embodiment 6
[0122] Figure 6 This is a structural diagram of a data caching device provided in Embodiment 6 of the present invention, the device comprises: a target header file determination module 610, a target table header information generation module 620, an attribute information determination module 630 and a reusable component generation module 640.
[0123] Among them, the target header file determination module 610 is used to determine the target header file from the file set including the header file according to the column header information of the target file when a trigger operation of storing the data in the target file into the database is detected; the header file includes a predefined column header and an attribute name corresponding to the predefined column header; the target column header information generation module 620 is used to determine the target column header to be read according to the column header information and the predefined column header in the target header file, and determine the column index information corresponding to the target column header in the target file and the target attribute name corresponding to the column index information; the attribute information determination module 630 is used to read the current row data in sequence according to the index information for the row data in the target file, and store the column data in the current row data and the target attribute name in correspondence in the reusable component; the reusable component generation module 640 is used to generate data sets based on the reusable components corresponding to each row of data and store them in the database. On the basis of the above technical solution, the target header file determination module is further used to determine the target header file from the file set according to the business type corresponding to the target file and the column header information.
[0124] On the basis of the above technical solution, the target header file determination module further includes: a first target header file generation unit, used to determine at least one target header file to be determined from the file set according to the business type of the target file; a second target header file generation unit, used to extract the column header information in the target file based on a data reading tool, and based on the data reading tool, determine a target header file including the column header information or consistent with the column header information from the at least one target header file to be determined. On the basis of the above technical solution, the target column header information generation module includes: a third column header generation unit, used to use the column header information as the target column header information when the column header information is consistent with a predetermined column header; determine the column value of the target column header in the target file, and use the column value as the index information;
[0125] The attribute name of the target list header information is retrieved, and a corresponding relationship between the index information and the attribute name is established, so that when reading data, the read data is stored under the corresponding attribute name based on the index information.
[0126] Based on the above technical solution, the attribute information determination module includes:
[0127] a target attribute name determining unit, configured to read the current column data according to the index information for each column data in the row data, and determine the target attribute name corresponding to the index information;
[0128] The attribute information determination unit is used to determine the attribute information of the reusable component corresponding to the current row data based on the column data and the target attribute name.
[0129] Based on the above technical solution, the reusable component generation module also includes: a data set generation unit, which is used to generate a data set according to the reusable components corresponding to each row of data in the target file; and a data cache unit, which is used to cache the data set to a database and / or a file to be cached.
[0130] On the basis of the above technical solutions, the device further includes:
[0131] A predefined reusable component creation module, used to create at least one predefined reusable component and add an annotation to the attribute information of the at least one predefined reusable component; the annotation attribute information of the annotation includes a predefined column header;
[0132] The header file generation module is used to identify the annotation information in each predefined reusable component according to the reflection mechanism, and generate a header file according to the annotation information, wherein the header file includes the predefined column header and the attribute name corresponding to the predefined column header.
[0133] The technical solution of the embodiment of the present invention determines the target header file from a file set including the header file according to the list header information of the target file when a trigger operation for storing the data in the target file into the database is detected, and determines the target list header according to the list header information and the predefined list header in the target header file. At the same time, the index information of the target list header in the target file and the target attribute name corresponding to the index information are determined. After determining the above information, each row data in the target file can be read in turn, and the row data can be written into a reusable component of the current row data, and the column data in the row data corresponding to the target attribute name in the reusable component. This solves the technical problem in the prior art that corresponding program code needs to be written when importing data into the database, and there is a cumbersome and complicated technical problem of data importing, and achieves the technical effect of conveniently and efficiently importing data into the database.
[0134] The data caching device provided in the embodiment of the present invention can execute the data caching method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0135] It is worth noting that the various units and modules included in the above-mentioned device are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present invention.
[0136] Embodiment 7
[0137] Figure 7 This is a structural diagram of a data retrieval device provided in Embodiment 7 of the present invention. The device includes: a target header file generation module 710, a document list header generation module 720 and a data writing module 730.
[0138] Among them, the target header file generation module 710 is used to generate a target header file according to the target list header triggered by the user when a trigger operation of exporting target data in the database to the target file is detected; the target header file includes the triggered target list header, the index information of the target list header and the attribute name corresponding to the target list header; the document list header generation module 720 is used to generate the document list header of the target document according to the attribute name corresponding to the target list header and the index information; the data writing module 730 is used to write each target data filled in the attribute information of each reusable component into the document list header of the target document in sequence according to the index information; the attribute information of the reusable component includes the attribute name and the data corresponding to the attribute name.
[0139] On the basis of the above technical solution, the target header file generating module is used to, when a trigger operation of exporting target data in the database to the target file is detected, before generating the target header file according to the target table header triggered by the user, further used to:
[0140] For each row of data in the target data, a reusable component to be used is created, and the corresponding attribute name is obtained according to the index information, and the attribute name is used as the attribute information of the reusable component to be used; for each row of data, the current row data is read in turn according to the index information, and the column data in the current row data is stored in correspondence with the corresponding attribute name to obtain a reusable component.
[0141] Based on the above technical solutions, the device also includes a data writing module, which is used to obtain the data filled in each attribute name for each reusable component, and write the data in sequence under the document list header of the target document according to the index information.
[0142] On the basis of the above-mentioned technical solutions, before the data writing module is used to generate the document list header of the target document according to the attribute name corresponding to the target list header and the index information, it is also used to: call the data reading tool to generate the document display style of the target document to display the imported data based on the document display style.
[0143] The technical solution of the embodiment of the present invention temporarily stores the target data in a reusable component when exporting the target data from the database, processes the reusable component based on a reflection mechanism, and then writes the data stored in the reusable component into the target file in sequence. This achieves the technical effect of exporting data from the database to the target document without modifying the corresponding program code, thereby improving the efficiency of data export.
[0144] The data retrieval device provided in the embodiment of the present invention can execute the data retrieval method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0145] It is worth noting that the various units and modules included in the above-mentioned device are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present invention.
[0146] Embodiment 8
[0147] Figure 8 A schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. Figure 8 A block diagram of an exemplary electronic device 80 suitable for use in implementing exemplary embodiments of the present invention is shown. Figure 8 The electronic device 80 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0148] like Figure 8 As shown, the electronic device 80 is in the form of a general computing device. The components of the electronic device 80 may include but are not limited to: one or more processors or processing units 801, a system memory 802, and a bus 803 connecting different system components (including the system memory 802 and the processing unit 801).
[0149] Bus 803 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus structures. For example, these 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.
[0150] The electronic device 80 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 80, including volatile and non-volatile media, removable and non-removable media.
[0151] The system memory 802 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 804 and / or cache memory 805. The electronic device 80 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 806 may be used to read and write non-removable, non-volatile magnetic media ( Figure 8 not shown, usually called a "hard drive"). Although Figure 8 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 803 via one or more data medium interfaces. The memory 802 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the embodiments of the present invention.
[0152] A program / utility 808 having a set (at least one) of program modules 807 may be stored, for example, in the memory 802, such program modules 807 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 807 generally perform the functions and / or methods of the embodiments described herein.
[0153] The 80 electronic device 80 may also communicate with one or more external devices 809 (e.g., keyboard, pointing device, display 810, etc.), may also communicate with one or more devices that enable a user to interact with the 80 electronic device 80, and / or communicate with any device that enables the 80 electronic device 80 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 811. Furthermore, the 80 electronic device 80 may also 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) through a network adapter 812. As shown, the network adapter 812 communicates with other modules of the 80 electronic device 80 through the bus 803. It should be understood that although Figure 8 Not shown, other hardware and / or software modules may be used in conjunction with electronic device 80, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0154] The processing unit 801 executes various functional applications and data processing by running programs stored in the system memory 802, such as implementing the data caching method and / or data retrieval method provided in the embodiments of the present invention.
[0155] Embodiment 9
[0156] Embodiment 5 of the present invention further provides a storage medium comprising computer executable instructions, wherein the computer executable instructions are used to execute a data caching method and / or a data retrieval method when executed by a computer processor.
[0157] The data caching method includes:
[0158] When a trigger operation of storing data in a target file into a database is detected, a target header file is determined from a file set including header files according to column header information of the target file; the header file includes a predefined column header and an attribute name corresponding to the predefined column header;
[0159] Determine the target column header to be read according to the column header information and the predefined column header in the target table header file, and determine the column index information corresponding to the target column header in the target file and the target attribute name corresponding to the column index information;
[0160] For the row data in the target file, read the current row data in sequence according to the index information, and store the column data in the current row data and the target attribute name in a reusable component in correspondence;
[0161] Based on the reusable components corresponding to each row of data, the data sets are generated and stored in the database.
[0162] or,
[0163] A data retrieval method, the method comprising:
[0164] When a trigger operation of exporting target data in a database to a target file is detected, a target header file is generated according to the target list header triggered by the user; the target header file includes the triggered target list header, index information of the target list header, and an attribute name corresponding to the target list header;
[0165] Generate a document list header of the target document according to the attribute name corresponding to the target list header and the index information;
[0166] The target data filled in the attribute information of each reusable component are sequentially written under the document list header of the target document according to the index information; the attribute information of the reusable component includes the attribute name and the data corresponding to the attribute name.
[0167] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0168] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0169] 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.
[0170] Computer program code for performing the operation of embodiments of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0171] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A data caching method, characterized in that: include: When a trigger operation of storing data in a target file into a database is detected, a target header file is determined from a file set including header files according to column header information of the target file; the header file includes a predefined column header and an attribute name corresponding to the predefined column header; Determine the target column header to be read according to the column header information and the predefined column header in the target table header file, and determine the column index information corresponding to the target column header in the target file and the target attribute name corresponding to the column index information; For the row data in the target file, read the current row data in sequence according to the index information, and store the column data in the current row data and the target attribute name in a reusable component in correspondence; Generate data sets based on the reusable components corresponding to each row of data and store them in the database; Wherein, determining the target header file from a file set including the header file according to the header information of the target file comprises: A target header file matching the column header information of the target file is determined from a plurality of header files stored in the file set according to the column header information.
2. The method according to claim 1, characterized in that The step of determining, from the plurality of header files stored in the file set according to the list header information, a target header file that matches the list header information of the target file comprises: According to the service type corresponding to the target file and the table header information, a target table header file is determined from the file set.
3. The method according to claim 2, characterized in that The step of determining a target header file from the file set according to the business type corresponding to the target file and the header information includes: Determining at least one target header file to be determined from the file set according to the business type of the target file; The column header information in the target file is extracted based on a data reading tool, and a target header file including the column header information or consistent with the column header information is determined from the at least one target header file to be determined based on the data reading tool.
4. The method according to claim 1, characterized in that: The step of determining a target column header to be read according to the column header information and a predefined column header in the target table header file, and determining column index information corresponding to the target column header in the target file and a target attribute name corresponding to the column index information includes: When the list header information is consistent with the predefined list header, the list header information is used as the target list header information; Determine a column value of the target column header in the target file, and use the column value as the index information; The attribute name of the target list header information is retrieved, and a corresponding relationship between the index information and the attribute name is established, so that when reading data, the read data is stored under the corresponding attribute name based on the index information.
5. The method according to claim 1, characterized in that The step of sequentially reading the current row data according to the index information and storing the column data in the current row data and the target attribute name in a corresponding manner in the reusable component includes: For each column of data in the row data, read the current column data according to the index information, and determine the target attribute name corresponding to the index information; Based on the column data and the target attribute name, determine the attribute information of the reusable component corresponding to the current row data.
6. The method according to claim 1, characterized in that The generating of data sets based on the reusable components corresponding to each row of data and merging and storing them in the database includes: Generate a data set according to the reusable components corresponding to each row of data in the target file; The data set is cached in a database and / or a file to be cached.
7. The method according to claim 1, characterized in that Also includes: Creating at least one predefined reusable component, and adding annotations to the property information of the at least one predefined reusable component; The annotation attribute information of the annotation includes a predefined column header; For each predefined reusable component, annotation information in the predefined reusable component is identified according to a reflection mechanism, and a header file is generated according to the annotation information. The header file includes a predefined column header and an attribute name corresponding to the predefined column header.
8. A data retrieval method, characterized in that: include: When a trigger operation of exporting target data in the database to a target file is detected, a target header file is generated according to the target table header triggered by the user; The target header file includes a triggered target list header, index information of the target list header, and an attribute name corresponding to the target list header; Generate a document list header of a target document according to the attribute name corresponding to the target list header and the index information; The target data filled in the attribute information of each reusable component are sequentially written under the document list header of the target document according to the index information; the attribute information of the reusable component includes the attribute name and the data corresponding to the attribute name.
9. The method according to claim 8, characterized in that Before writing each target data filled in the attribute information of each reusable component into the document list header of the target document in sequence according to the index information, the method further includes: For each row of data in the target data, a reusable component to be used is created, and a corresponding attribute name is obtained according to the index information, and the attribute name is used as the attribute information of the reusable component to be used; For each row of data, the current row of data is read in sequence according to the index information, and the column data in the current row of data is stored correspondingly with the corresponding attribute name to obtain a reusable component.
10. The method according to claim 9, characterized in that The step of sequentially writing the data filled in the attribute information of each reusable component under the document list header of the target document according to the index information includes: For each reusable component, the data filled in each attribute name is obtained, and the data is sequentially written under the document list header of the target document according to the index information.
11. The method according to claim 8, characterized in that Before generating the document list header of the target document according to the attribute name corresponding to the target list header and the index information, the method further includes: A data reading tool is called to generate a document display style of the target document so as to display the imported data based on the document display style.
12. A data cache device, characterized in that: include: A target header file determination module is used to determine a target header file from a file set including header files according to column header information of the target file when a trigger operation of storing data in the target file into a database is detected; the header file includes a predefined column header and an attribute name corresponding to the predefined column header; A target column header information generating module, used to determine the target column header to be read according to the column header information and the predefined column header in the target column header file, and determine the column index information corresponding to the target column header in the target file and the target attribute name corresponding to the column index information; An attribute information determination module, for sequentially reading the current row data according to the index information for the row data in the target file, and storing the column data in the current row data and the target attribute name in a reusable component in correspondence; A reusable component generation module is used to generate data sets based on the reusable components corresponding to each row of data and store them in the database; Wherein, the target header file determination module is specifically used for: A target header file matching the column header information of the target file is determined from a plurality of header files stored in the file set according to the column header information.
13. A data retrieval device, characterized in that: include: A target header file generation module is used to generate a target header file according to a target list header triggered by a user when a trigger operation of exporting target data in a database to a target file is detected; the target header file includes a triggered target list header, index information of the target list header, and an attribute name corresponding to the target list header; A document list header generation module, used to generate a document list header of a target document according to an attribute name corresponding to the target list header and the index information; The data writing module is used to write the target data filled in the attribute information of each reusable component into the document list header of the target document in sequence according to the index information; the attribute information of the reusable component includes the attribute name and the data corresponding to the attribute name.
14. An electronic device, characterized in that: The electronic device comprises: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the data caching method described in any one of claims 1 to 7 or the data retrieval method described in any one of claims 8 to 11.
15. A storage medium comprising computer executable instructions, wherein the computer executable instructions, when executed by a computer processor, are used to execute the data caching method according to any one of claims 1 to 7 or the data retrieval method according to any one of claims 8 to 11.
Citation Information
Patent Citations
Data synchronization method and device and server
CN110334152A
Multi-column joint storage method based on column storage
CN110413624A