Disclosure of Invention
In order to solve the technical problem or at least partially solve the technical problem, embodiments of the present invention provide a method, an apparatus, an electronic device, and a readable storage medium for acquiring page data.
In view of this, in a first aspect, an embodiment of the present invention provides a method for acquiring page data, including:
determining a page ID of a target page according to a received page request aiming at the target page;
determining a target sub-template corresponding to the page ID from a preset template library according to the page ID, wherein the sub-template corresponds to a sub-region divided by the target page, and the target page comprises at least one sub-region;
acquiring data corresponding to each target sub-template;
and integrating the data corresponding to all the target sub-templates to obtain the data of the target page.
In a possible embodiment, the determining, by the page request, a target sub-template corresponding to the page ID from a preset template library according to the page ID includes:
determining a sub-template corresponding to the page ID from a preset template library according to the page ID;
and determining a target sub-template matched with the attribute information of the target page in the sub-templates according to the attribute information of each sub-template in the sub-templates.
In one possible embodiment, the acquiring data corresponding to the target sub-template includes:
determining a template expression corresponding to the target sub-template, and acquiring data corresponding to the target sub-template by executing the template expression;
and/or
And acquiring elements corresponding to the target sub-template, and determining data corresponding to the target sub-template according to the elements.
In a possible embodiment, the page request includes attribute information of the target page, and determining data corresponding to the target sub-template according to the element includes:
determining a target element matched with the attribute information of the target page in the elements according to the attribute information of the elements;
acquiring the configuration content of the target element;
if the configuration content is preset static data, acquiring the static data as data corresponding to the target sub-template;
and if the configuration content is a preset page expression, acquiring data corresponding to the target sub-template through the page expression.
In one possible embodiment, before acquiring data corresponding to each of the target sub-templates, the method further includes:
acquiring a page expression corresponding to the page ID according to the page request, and executing the page expression to obtain dynamic data corresponding to the page expression;
acquiring data corresponding to the target template through a page expression in the configuration content of the target element, wherein the data includes:
and determining data corresponding to the page expression in the configuration content of the target element from the dynamic data as data corresponding to the target sub-template.
In a possible embodiment, integrating data corresponding to all target sub-templates to obtain data of the target page includes:
determining the position of a sub-area corresponding to each target sub-module in the target page;
and integrating data corresponding to all the target sub-templates according to the positions of the sub-regions corresponding to all the target sub-templates in the target page to obtain the data of the target page.
In one possible embodiment, the method further comprises:
acquiring a page rule corresponding to the page ID according to the page request, and executing the page rule to obtain rule data;
and after the data of the target page is obtained, screening the data of the target page according to the rule data to obtain the data which accords with the rule data, paging the screened data according to the page number in the page request, and sending the paged data to the terminal.
In a second aspect, an embodiment of the present invention further provides an apparatus for acquiring page data, including:
the page ID determining module is used for determining the page ID of the target page according to the received page request aiming at the target page;
the target sub-module determining module is used for determining a target sub-module corresponding to the page ID from a preset template library according to the page ID, wherein the sub-module corresponds to a sub-region divided by the target page, and the target page comprises at least one sub-region;
the data acquisition module is used for acquiring data corresponding to each target sub-template;
and the data integration module is used for integrating the data corresponding to all the target sub-templates to obtain the data of the target page.
In a third aspect, an embodiment of the present invention further provides an electronic device, including: a processor, a memory, a communication interface, and a bus;
the processor, the memory and the communication interface complete mutual communication through the bus;
the communication interface is used for information transmission between external devices;
the processor is configured to call program instructions in the memory to perform the steps of the method for acquiring page data of the first aspect.
In a fourth aspect, an embodiment of the present invention further provides a readable storage medium, where the readable storage medium stores computer instructions, and the computer instructions cause a computer to execute the steps of the method for acquiring page data according to the first aspect.
Compared with the prior art, the method for acquiring the page data provided by the embodiment of the invention has the advantages that after the page request aiming at the target page is received, the page ID of the target page is determined according to the page request, the target sub-template corresponding to the page ID is determined from the pre-constructed template library according to the page ID, wherein the sub-template corresponds to the sub-region divided by the target page, one target page possibly comprises a plurality of sub-regions, then the data corresponding to each target sub-module is determined according to the target sub-template, and the data corresponding to all the target sub-templates are integrated to obtain the data of the target page. According to the scheme, when page data integration is carried out, the target sub-templates corresponding to the pages can be obtained directly from the preset module library, the full-scale templates do not need to be developed again for each page, then the data corresponding to each target sub-template is obtained, and finally all data required by the pages can be obtained by integrating the data corresponding to all the target sub-templates.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
Fig. 1 is a flowchart of a method for acquiring page data according to an embodiment of the present invention, as shown in fig. 1, the method includes:
s11, determining the page ID of the target page according to the received page request aiming at the target page.
The page ID is the unique identification of the page, the page ID and the page are in one-to-one correspondence, and one page ID corresponds to only one page.
The page request is used for requesting page data corresponding to a target page.
Alternatively, the page request is terminal-transmitted/implemented, wherein the terminal may be implemented in various forms, for example, a mobile terminal such as a mobile phone, a smart phone, a notebook computer, a PAD (tablet), a PMP (portable multimedia player), a navigation device, etc., and a fixed terminal such as a digital TV, a desktop computer, etc.
S12, determining a target sub-template corresponding to the page ID from a preset template library according to the page ID, wherein the sub-template corresponds to sub-regions divided by the target page, and the target page comprises at least one sub-region.
In this embodiment, the target page is divided according to a preset page division rule, the target page is divided into at least one sub-region, and then each sub-region may correspond to one or more sub-templates. The page division rule is preset according to requirements, for example, if the target page includes a text title and a picture, the target page can be divided into two sub-regions, one sub-region is a region corresponding to the text title, the other sub-region is a region corresponding to the picture, and the positions of the divided sub-regions in the target page are different, that is, the sub-regions are not overlapped.
In a possible implementation manner, the determining, by the page request, a target sub-template corresponding to the page ID from a preset template library according to the page ID includes:
s121: and determining a sub-template corresponding to the page ID from a preset template library according to the page ID.
The page ID is the unique identification of the target page, so the sub-template corresponding to the page ID is the sub-template corresponding to the target page. Since the target page may be divided into a plurality of sub-regions, each sub-region may correspond to one or more sub-templates in the template library, however, since both the sub-template itself and the target page itself have some attributes, there may be sub-templates in the sub-templates corresponding to the sub-regions that conflict with the attributes of the target page, for example, a certain sub-region corresponds to a sub-template containing a picture, and there may be many sub-templates containing pictures in the template library, but these sub-templates containing pictures are not necessarily applicable to the target page. Therefore, in this embodiment, sub-modules obtained according to the page ID need to be screened, and sub-modules having conflicts with the attributes of the target page are removed, so that the target sub-page conforming to the attributes of the target page is left. In this embodiment, page data needs to be acquired according to a target sub-template corresponding to a target page, so in order to acquire all page data required by the target page, it is first ensured that all target sub-templates corresponding to the target page can be acquired, which requires acquiring all sub-modules corresponding to the target page, and then all the acquired sub-modules are screened through the following S122, so that all target sub-modules meeting the requirements of the target page are determined.
S122: and determining a target sub-template matched with the attribute information of the target page in all the sub-templates according to the attribute information of each sub-template in all the sub-templates.
For example, since the sub-templates are preset and all have certain attributes, by matching the attributes of the sub-templates with the attributes of the target page, the sub-module whose attributes match with the attributes of the target page is determined as the target sub-module, that is, the sub-module that can be displayed in the target page, for example: the attribute of the sub-template A is 'only displayed in the range of version 5.0.0-5.1.0', and the attribute of the target page is 'displayed in the client of version 5.1.2', the attribute of the sub-template A is not matched with the attribute of the target page, and the sub-template A is not the target sub-template. The same similar attributes are a crowd label, whether to log in, the online and offline time, dynamic display and the like.
In a possible implementation manner, the template library includes a local template library and a remote template library (for example, the remote template library may be stored in Redis, which is a non-relational database), when determining all sub-templates corresponding to the page ID, first, whether all sub-templates matching the page ID exist in the local template library is searched according to the page ID, and if all sub-templates matching the page ID do not exist in the locally stored template library, the sub-templates matching the page ID stored in the remote template library are read, so as to determine all sub-templates matching the page ID.
And S13, acquiring data corresponding to each target sub-template.
In one possible implementation manner, the data corresponding to each target sub-module is obtained through one or two (specifically, one or two are determined according to specific situations) of the following manners:
the first method is as follows: and determining a template expression corresponding to the target sub-template, and acquiring data corresponding to the target sub-template by executing the template expression.
The template expression is a preset expression corresponding to a target sub-template, the expression is used for acquiring data, the data acquisition is divided into two types, one type is the acquisition of the data of the whole sub-template, and the returned data and structure of the whole sub-template (including the position of a sub-area corresponding to the sub-template in a target page and the distribution form of the data in the sub-template) are obtained. The other is simple data acquisition, that is, data fragments in the sub-template are smaller in granularity, for example, data corresponding to the sub-template includes first data and second data, the acquisition of the data of the whole sub-template is that the first data and the second data are both acquired, and the simple data acquisition is that only the first data or the second data is acquired, that is, only partial data of the sub-template is acquired, but not all data. In this embodiment, the data and structure corresponding to the whole sub-template are obtained in this step, and the method is suitable for a scenario in which no page dynamic configuration is required and the data completely depends on the output of the service interface.
The second method comprises the following steps: and acquiring elements corresponding to the target sub-template, and determining data corresponding to the target sub-template according to the elements.
In one possible implementation manner, the page request includes attribute information of the target page, and the data corresponding to the target sub-template is determined according to the element, including the following steps:
s131: and determining a target element matched with the attribute information of the target page in the elements according to the attribute information of the elements.
One sub-module may have a plurality of elements, each element has its own attribute information, and only when the attribute information of the element itself matches with the attribute information of the target page, the data corresponding to the element can be displayed in the target page, so that the elements are screened according to the attribute information of the element, and the element whose attribute information matches with the attribute information of the target page is determined to be the target element, that is, the element that can be displayed in the target page. The process of element screening is similar to the process of template screening, and the difference is only that the processed objects are different, the elements are child nodes of the child templates, and the granularity is finer.
S132: and acquiring the configuration content of the target element.
The configuration content of the target element is the type of data corresponding to the target element, and is generally divided into static data and dynamic data, wherein the static data is fixed content set in advance, and the dynamic data is content obtained by executing a page expression.
S133: and if the configuration content is preset static data, acquiring the static data as data corresponding to the target sub-template.
S134: and if the configuration content is a preset page expression, acquiring data corresponding to the target sub-template through the page expression.
The page expression is a method required to be called for acquiring dynamic data of a page, and the method comprises a local method and a remote RPC method, wherein the local method is a method only stored locally and can be directly called, and the Remote Procedure Call (RPC) is a remote procedure call which requests service from a remote computer program through a network.
In one possible embodiment, before acquiring data corresponding to each of the target sub-templates, the method further includes: and acquiring all page expressions corresponding to the page ID according to the page request, executing the all page expressions (including but not limited to execution in an asynchronous calling mode), acquiring dynamic data corresponding to the all page expressions, and storing the dynamic data into context environment variables of a rendering thread of a target page for subsequent use.
After receiving the page request, all the page expressions corresponding to the page ID of the target page are asynchronously called, so that when the corresponding data is obtained through the page expression in the configuration content of the target element, the data corresponding to the page expression is normally obtained, and therefore, the data corresponding to the page expression in the configuration content of the target element is directly searched from all the data obtained according to all the page expressions. If the data corresponding to the page expression is not completely acquired when the corresponding data is acquired through the page expression in the configuration content of the target element, the waiting is blocked until the data of the page expression is completely acquired, and the execution speed of the page expression can be increased to avoid the situation, so that when the page expression corresponding to the target element is determined, the page expression is executed in advance and the corresponding data is acquired, and the corresponding data can be directly acquired without waiting for the execution of the page expression.
And S14, integrating the data corresponding to all the target sub-templates to obtain the data of the target page.
In this embodiment, each target sub-template corresponds to one sub-region of the target page, so that the position of each sub-region corresponding to each target sub-template in the target page is determined, then the position of the data corresponding to each sub-module can be determined according to the position of each sub-region corresponding to each target sub-template in the target page, and then the integration of the data corresponding to all the target sub-templates is completed according to the position of the data corresponding to each sub-module, so as to obtain the data of the target page. In one possible embodiment, the method further comprises:
and acquiring a page rule corresponding to the page ID according to the page request, and executing the page rule to obtain rule data, wherein the page rule is preset according to requirements.
And after the data of the target page is obtained, screening the data of the target page according to the rule data to obtain the data which accords with the rule data, paging the screened data according to the page number in the page request, and sending the paged data to the terminal.
The obtained data of the target page is further screened through the rule data, and the data blocks of the unnecessary sub-templates, elements or deeper sub-nodes are generally deleted. Or alternatively, reserved, and not needed for deletion. The corresponding rule types are: pit priority rules, ABTest selection rules, random distribution rules, advertisement data acquisition rules, and the like.
When the obtained data of the target page is further screened according to the rule data, sub-template association logic processing is further performed, for example, the sub-template A and the sub-template B have an association relationship, and in the previous screening processing, the sub-template A is removed, and in the step, the sub-template B is also removed.
Note that the order of the numbers used to identify the steps in this embodiment does not necessarily indicate the execution order of the steps.
The method for acquiring page data provided by the embodiment of the invention comprises the steps of determining the page ID of a target page according to a page request after receiving the page request aiming at the target page, determining all target sub-templates corresponding to the page ID from a pre-constructed template library according to the page ID, wherein one sub-template corresponds to one sub-region divided by the target page, one target page possibly comprises a plurality of sub-regions, then determining corresponding data according to the target sub-templates, and integrating the data corresponding to all the target sub-templates according to the positions of the sub-regions corresponding to all the target sub-templates in the target page to obtain the data of the target page. According to the scheme, when page data integration is carried out, the target sub-templates corresponding to the pages can be obtained directly from the preset module library, the full-scale templates do not need to be developed again for each page, then the data corresponding to each target sub-template is obtained, and finally all data required by the pages can be obtained by integrating the data corresponding to all the target sub-templates.
The method for acquiring the page data provided by the embodiment is suitable for the static loading and dynamic loading pages.
As shown in fig. 2, an embodiment of the present invention further provides an apparatus for acquiring page data, where the apparatus may include:
a page ID determining module 201, configured to determine a page ID of a target page according to a received page request for the target page;
a target sub-module determining module 202, configured to determine, according to the page ID, all target sub-templates corresponding to the page ID from a preset template library, where one sub-template corresponds to one sub-region divided by the target page, and the target page includes at least one sub-region;
a data obtaining module 203, configured to obtain data corresponding to each target sub-template;
and the data integration module 204 is configured to integrate data corresponding to all target sub-templates to obtain data of the target page.
In a possible embodiment, the page request includes attribute information of the target page, and the sub-module determining module 202 determines, according to the page ID, a target sub-template corresponding to the page ID from a preset template library, including:
determining a sub-template corresponding to the page ID from a preset template library according to the page ID;
and determining a target sub-template matched with the attribute information of the target page in the sub-templates according to the attribute information of each sub-template in the sub-templates.
In one possible embodiment, the data obtaining module 203 obtains data corresponding to the target sub-template, including:
determining a template expression corresponding to the target sub-template, and acquiring data corresponding to the target sub-template by executing the template expression;
and/or
And acquiring elements corresponding to the target sub-template, and determining data corresponding to the target sub-template according to the elements.
In a possible embodiment, the page request includes attribute information of the target page, and the determining, by the data obtaining module 203, data corresponding to the target sub-template according to the element includes:
determining a target element matched with the attribute information of the target page in the elements according to the attribute information of the elements;
acquiring the configuration content of the target element;
if the configuration content is preset static data, acquiring the static data as data corresponding to the target sub-template;
and if the configuration content is a preset page expression, acquiring data corresponding to the target sub-template through the page expression.
In a possible embodiment, the data integration module 204 integrates data corresponding to all target sub-templates to obtain data of the target page, including:
determining the position of a sub-area corresponding to each target sub-module in the target page;
and integrating data corresponding to all the target sub-templates according to the positions of the sub-regions corresponding to all the target sub-templates in the target page to obtain the data of the target page.
In one possible embodiment, the apparatus further comprises:
the dynamic data acquisition module is used for acquiring all page expressions corresponding to the page ID according to the page request after receiving the page request sent by the terminal, and executing all the page expressions to obtain dynamic data corresponding to all the page expressions;
the data obtaining module 203 obtains data corresponding to the target template through a page expression in the configuration content of the target element, including:
and determining data corresponding to the page expression in the configuration content of the target element from the dynamic data as data corresponding to the target sub-template.
In one possible embodiment, the apparatus further comprises:
the rule data determining module is used for acquiring a page rule corresponding to the page ID according to the page request and executing the page rule to obtain rule data;
and the data screening module is used for screening the data of the target page according to the rule data to obtain the data which accords with the rule data after the data of the target page is obtained, paging the screened data according to the page number in the page request and sending the paged data to the terminal.
As shown in fig. 3, the present embodiment discloses an electronic device, including: a processor 301, a memory 302, a communication interface 303, and a bus 304;
the processor 301, the memory 302 and the communication interface 303 complete mutual communication through the bus 304;
the communication interface 303 is used for information transmission between external devices; the external device is, for example, a user equipment UE;
the processor 301 is configured to invoke program instructions in the memory 302 to perform methods as provided by the method embodiments, including, for example:
determining a page ID of a target page after receiving a page request aiming at the target page sent by a terminal;
determining all target sub-templates corresponding to the page ID from a preset template library according to the page ID, wherein one sub-template corresponds to one sub-region divided by the target page, and the target page comprises at least one sub-region;
acquiring data corresponding to each target sub-template;
and integrating data corresponding to all the target sub-templates according to the positions of the sub-regions corresponding to the target sub-templates on the target page to obtain the data of the target page.
Fig. 4 is a schematic structural diagram of an electronic device according to another embodiment of the present invention. The mobile terminal 400 shown in fig. 4 includes: at least one processor 401, memory 402, at least one network interface 404, and other user interfaces 403. The various components in the mobile terminal 400 are coupled together by a bus system 405. It is understood that the bus system 405 is used to enable connection communication between these components. The bus system 405 includes a power bus, a control bus, and a status signal bus in addition to a data bus. For clarity of illustration, however, the various buses are labeled as bus system 405 in fig. 4.
The user interface 403 may include, among other things, a display, a keyboard, or a pointing device (e.g., a mouse, trackball, touch pad, or touch screen, among others.
It will be appreciated that memory 402 in embodiments of the invention may be either volatile memory or nonvolatile memory, or may include both volatile and nonvolatile memory. The non-volatile Memory may be a Read-Only Memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically Erasable PROM (EEPROM), or a flash Memory. Volatile Memory can be Random Access Memory (RAM), which acts as external cache Memory. By way of example, but not limitation, many forms of RAM are available, such as Static random access memory (Static RAM, SRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic random access memory (Synchronous DRAM, SDRAM), Double Data rate Synchronous Dynamic random access memory (ddr SDRAM ), Enhanced Synchronous SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), and direct memory bus RAM (DRRAM). The memory 402 described herein is intended to comprise, without being limited to, these and any other suitable types of memory.
In some embodiments, memory 402 stores the following elements, executable units or data structures, or a subset thereof, or an expanded set thereof: an operating system 4021 and application programs 4022.
The operating system 4021 includes various system programs, such as a framework layer, a core library layer, a driver layer, and the like, and is configured to implement various basic services and process hardware-based tasks. The application programs 4022 include various application programs, such as a Media Player (Media Player), a Browser (Browser), and the like, for implementing various application services. A program for implementing the method according to the embodiment of the present invention may be included in the application 4022.
In this embodiment of the present invention, by calling a program or an instruction stored in the memory 402, specifically, a program or an instruction stored in the application 4022, the processor 401 is configured to execute the method steps provided by the method embodiments, for example, including:
determining a page ID of a target page after receiving a page request aiming at the target page sent by a terminal;
determining all target sub-templates corresponding to the page ID from a preset template library according to the page ID, wherein one sub-template corresponds to one sub-region divided by the target page, and the target page comprises at least one sub-region;
acquiring data corresponding to each target sub-template;
and integrating data corresponding to all the target sub-templates according to the positions of the sub-regions corresponding to the target sub-templates on the target page to obtain the data of the target page.
The method disclosed in the above embodiments of the present invention may be applied to the processor 401, or implemented by the processor 401. The processor 401 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 401. The Processor 401 may be a general-purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable Gate Array (FPGA) or other programmable logic device, discrete Gate or transistor logic device, or discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software elements in the decoding processor. The software elements may be located in ram, flash, rom, prom, or eprom, registers, among other storage media that are well known in the art. The storage medium is located in the memory 402, and the processor 401 reads the information in the memory 402 and completes the steps of the method in combination with the hardware.
Embodiments of the present invention also provide a readable storage medium, where the non-transitory computer readable storage medium stores computer instructions, where the computer instructions cause the computer to execute the method provided by the method embodiments, for example, including:
determining a page ID of a target page after receiving a page request aiming at the target page sent by a terminal;
determining all target sub-templates corresponding to the page ID from a preset template library according to the page ID, wherein one sub-template corresponds to one sub-region divided by the target page, and the target page comprises at least one sub-region;
acquiring data corresponding to each target sub-template;
and integrating data corresponding to all the target sub-templates according to the positions of the sub-regions corresponding to the target sub-templates on the target page to obtain the data of the target page.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
It is noted that, in this document, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
Through the above description of the embodiments, those skilled in the art will clearly understand that the methods described in the embodiments of the present invention can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention or the method according to some parts of the embodiments.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.