CN107766344B - Template rendering method and device and browser - Google Patents

Template rendering method and device and browser Download PDF

Info

Publication number
CN107766344B
CN107766344B CN201610671634.9A CN201610671634A CN107766344B CN 107766344 B CN107766344 B CN 107766344B CN 201610671634 A CN201610671634 A CN 201610671634A CN 107766344 B CN107766344 B CN 107766344B
Authority
CN
China
Prior art keywords
template
service
rendering
unit
business
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610671634.9A
Other languages
Chinese (zh)
Other versions
CN107766344A (en
Inventor
刘威
尹利民
陈旭东
王建
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201610671634.9A priority Critical patent/CN107766344B/en
Publication of CN107766344A publication Critical patent/CN107766344A/en
Application granted granted Critical
Publication of CN107766344B publication Critical patent/CN107766344B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/958Organisation or management of web site content, e.g. publishing, maintaining pages or automatic linking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms

Abstract

The application provides a template rendering method, a template rendering device and a browser, wherein the method comprises the following steps: acquiring a webpage browsing request of a user; determining a template corresponding to the webpage browsing request; and performing template rendering on data returned by calling the business service based on the template to generate a corresponding webpage, wherein the data comprises: the method comprises the steps that data of business services are directly obtained from a service factory in a template rendering process; and returning the webpage to the user. In the embodiment of the application, the corresponding relation between the template and the business service is established by expanding the rendering engine, the template rendering can directly use the business service to execute the returned data, so that the controller does not need to assemble the business data for the template, but directly fills the service data of the business layer into the determined template, thereby greatly reducing the code compiling of the controller and improving the execution efficiency of the template rendering operation.

Description

Template rendering method and device and browser
Technical Field
The present application relates to the field of network technologies, and in particular, to a method and an apparatus for template rendering, and a browser.
Background
In recent years, with the development of website technology, billions of page visits are possible each day, and the rapid display of commodity information to users and the display of different commodity information for different users have become the main means of competition of various large websites. However, due to the existence of a large amount of commodity information, the information to be displayed is diversified. Before template rendering, a Controller needs to call a plurality of application services to assemble all template data required by the template rendering, and simultaneously needs to select which template is used to render a page, then a rendering engine fills template data (Model) into the template to obtain final page source code (html), and finally, the page source code is returned to a user browser.
In the existing template rendering, because the Controller needs to call a plurality of business services to assemble data required by the template rendering, the code compiling of the Controller is increased, and the execution efficiency of the template rendering operation is reduced.
Disclosure of Invention
In view of this, the present application provides a method and an apparatus for template rendering, and a browser, so as to solve the technical problem in the prior art that the execution efficiency of the template rendering operation is reduced because a controller needs to invoke a plurality of business services to assemble data required for template rendering, and code writing of the controller is increased.
Specifically, the method is realized through the following technical scheme:
a first aspect provides a method of template rendering, comprising:
acquiring a webpage browsing request of a user;
determining a template corresponding to the webpage browsing request;
and performing template rendering on data returned by calling the business service based on the template to generate a corresponding webpage, wherein the data comprises: the method comprises the steps that data of business services are directly obtained from a service factory in a template rendering process;
and returning the webpage to the user.
Optionally, the template rendering is performed based on data returned by the template calling service, and generating a corresponding webpage includes:
reading the template;
analyzing the read template into an abstract syntax tree;
traversing each node in the abstract syntax tree;
when a node is traversed, searching a corresponding variable value in the template rendering context object by using the variable name of the node;
if the corresponding variable value is found, rendering the node by using the variable value;
if the corresponding variable value is not found, searching the corresponding business service from the service factory by using the variable name;
if the corresponding business service is found, executing the business service, and rendering the node by taking the data for executing the business service as a variable value;
and generating a webpage after rendering each node in the abstract syntax tree.
Optionally, the abstract syntax tree includes variable nodes, and the variable nodes are used to indicate that the nodes are replaced with corresponding variable values in the rendering process.
Optionally, the method further includes:
before template rendering, collecting all business services by using a dependent injection container;
and establishing a corresponding relation between the business service and the service name so as to find the corresponding business service according to the service name.
Optionally, the collecting all the business services by using the dependent injection container includes:
traversing all service object methods in the dependent injection container after the dependent injection container is initialized;
judging whether the method has an annotation with a specific annotation identifier, if so, determining that the method is a service method, and using the value of the annotation as a key in a service factory;
and packaging the service method into a service result proxy object, and storing the service result proxy object as a value into a service factory so as to search the service result proxy object according to keys in the service factory during template rendering.
A second aspect provides a stencil rendering apparatus comprising:
the acquisition unit is used for acquiring a webpage browsing request of a user;
the first determining unit is used for determining a template corresponding to the webpage browsing request;
a first rendering unit, configured to perform template rendering on data returned by the template-based calling business service, where the data includes: the method comprises the steps that data of business services are directly obtained from a service factory in a template rendering process;
the generating unit is used for generating a corresponding webpage according to the rendering result of the first rendering unit;
and the sending unit is used for returning the webpage to the user.
Optionally, the rendering unit includes:
a reading unit for reading the template;
the analysis unit is used for analyzing the read template into an abstract syntax tree;
the first traversal unit is used for traversing each node in the abstract syntax tree;
the first judging unit is used for judging whether a corresponding variable value is searched in the template rendering context object by using the variable name of the node when the first traversal unit traverses to one node;
a second rendering unit, configured to render the node using the variable value when the first determining unit determines that the corresponding variable value is found in the template rendering context object;
a second judging unit, configured to judge whether the corresponding service is found from a service factory by using the variable name when the first judging unit judges that the corresponding variable value is not found in the template rendering context object;
the executing unit is used for executing the business service when the second judging unit judges that the corresponding business service is found;
and the third rendering unit is used for rendering the node by taking the data of the business service executed by the execution unit as a variable value.
Optionally, the method further includes:
the collection unit is used for collecting all business services by utilizing a dependent injection container before template rendering;
and the establishing unit is used for establishing the corresponding relation between the business service and the service name so as to find the corresponding business service according to the service name.
Optionally, the collecting unit includes:
the second traversal unit is used for traversing all the methods of the service objects in the dependence injection container after the dependence injection container is initialized;
a third judging unit, configured to judge whether there is an annotation identified by a specific annotation on the method;
a second determination unit configured to determine that the method is a service method and to use a value of an annotation as a key in a service factory when the third judgment unit judges that the annotation is present;
the packaging unit is used for packaging the service method into a service result proxy object;
and the storage unit is used for saving the service structure proxy object as a value to a service factory so as to search the service result proxy object according to a key in the service factory during template rendering.
A third aspect provides a browser comprising: a control module, a template and a service processing module, wherein,
the control module is used for sending a template selection request corresponding to a webpage browsing request to the template when receiving the webpage browsing request sent by a user;
the template is used for selecting the template corresponding to the webpage browsing request when the template selection request is received, and sending a calling request of business service to the business processing module;
the service processing module is used for generating corresponding data according to the call request when receiving the call request and returning the data to the template; wherein the data comprises: the method comprises the steps that data of business services are directly obtained from a service factory in a template rendering process;
and the template is used for receiving the data returned by the service processing module, performing template rendering according to the data, generating a corresponding webpage and returning the webpage to the user.
In the embodiment of the application, the corresponding relation between the template and the business service is established by expanding the rendering engine, the template rendering can directly use the business service to execute the returned data, so that the controller does not need to assemble the business data for the template, but directly fills the service data of the business layer into the determined template, thereby greatly reducing the code compiling of the controller and improving the execution efficiency of the template rendering operation.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
FIG. 1 is a flow chart of a method for template rendering according to an embodiment of the present disclosure;
FIG. 2 is a flowchart of a specific implementation process of template rendering according to an embodiment of the present disclosure;
fig. 3 is a hardware structure diagram of a device in which a template rendering apparatus according to an embodiment of the present application is located;
FIG. 4 is a schematic structural diagram of an apparatus for template rendering according to an embodiment of the present disclosure;
FIG. 5 is another structural diagram of an apparatus for template rendering according to an embodiment of the present disclosure;
FIG. 6 is a schematic structural diagram of a template rendering apparatus provided in an embodiment of the present application;
FIG. 7 is a schematic diagram of an application of a webx framework provided in an embodiment of the present application.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this application and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present application. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
Please refer to fig. 1, which is a flowchart illustrating a method for template rendering according to an embodiment of the present disclosure; in this embodiment, taking a WEB development mode, that is, an MVC mode as an example, the method includes:
step 101: acquiring a webpage browsing request of a user;
the service platform receives a web browsing request of a user, where the web browsing request usually carries a Uniform Resource Locator (URL) specified by the user: the service platform in this embodiment may be a server or a Controller, such as a Controller (Controller) in the MVC mode.
Step 102: determining a template corresponding to the webpage browsing request;
in this step, the service platform may determine a corresponding template according to the URL carried in the web browsing request, where the template may be a Velocity template or the like, for example, using Java language as an example.
Step 103: based on the template, calling data returned by the business service to perform template rendering, and generating a corresponding webpage;
in this embodiment, a specific implementation process of template rendering is as follows: the template is parsed into an abstract syntax tree and rendering of the entire page is accomplished by traversing each node in the rendered abstract syntax tree. In the process of traversing, every time a node is touched, the variable name of the node is used for searching in a template rendering context object (context), and if the variable name is found, the variable value is used for rendering the node. The method is a method of a common template rendering engine, and the method is expanded to a certain extent on the basis of a conventional template rendering engine, namely if the variable name of the node is not found in context, the variable name of the node is used for searching the corresponding business service from a service factory; if a business service is found, the business service is executed and the node is rendered with the return data of the executing business service as variable values. And finally, generating a webpage after each node in the abstract syntax tree is rendered. It should be noted that, in this embodiment, the web page is html source code.
The specific implementation process of this step is shown in fig. 2, and will not be described herein again.
Step 104: and returning the webpage to the user.
That is, the web page is returned to the user browser, so that the browser converts the web page and displays the converted web page to the user.
In this embodiment, since the rendered page is html source code, and the html source code can only be displayed to the user through the browser, the html source code needs to be returned to the user browser first, and the browser displays the converted page to the user.
In the embodiment of the application, the corresponding relation between the template and the business service is established by expanding the rendering engine, the template rendering can directly use the business service to execute the returned data, and the Controller does not need to assemble the business data for the template, but directly fills the business service data of the business layer into the determined template, so that the code writing of the Controller is greatly reduced, and the execution efficiency of the template rendering operation is improved.
Referring to fig. 2, a flowchart of a template rendering process according to an embodiment of the present disclosure is shown, where the embodiment takes a service platform as an example and specifically includes:
step 201: reading the template;
step 202: analyzing the read template into an abstract syntax tree;
step 203: traversing each node in the abstract syntax tree;
step 204: judging the node type of each traversed node, and if the node type is a variable, executing step 205; if the text data is the text data, executing step 210;
step 205: judging whether the variable name of the node searches a corresponding variable value in a template rendering context object (context); if so, go to step 206; otherwise, go to step 207;
step 206: rendering the nodes by using the variable values, and then finishing rendering;
step 207: judging whether the corresponding business service is searched from a service factory by using the variable name; if so, go to step 208; otherwise, go to step 209;
step 208: executing the business service, and rendering the node by taking data for executing the business service as a variable value;
step 209: rendering is abnormal;
step 210; rendering the node using the text data;
step 211: and generating a webpage after rendering each node in the abstract syntax tree.
That is, in this embodiment, the template is parsed into an abstract syntax tree, and the entire page rendering is accomplished by traversing each node in the rendering abstract syntax tree. In the process of traversing, every time a node is touched, the variable name of the node is used for searching in a template rendering context object (context), and if the variable name is found, the variable value is used for rendering the node. This is a way of a general template rendering engine, and in the embodiment of the present application, a certain extension is performed on the basis of a conventional template rendering engine, that is, if the variable name is not found in a template rendering context object (context), the variable name is used to search a corresponding business service from a service factory; if a business service is found, the business service is executed, and the node is rendered by taking the return data of the business service as a variable value. Taking a velocity rendering engine (for example, an open source template rendering engine in Java language) as an example, the implementation manner of the modified triggered template rendering is as follows:
Figure BDA0001079294370000081
Figure BDA0001079294370000091
in this way, Velocity parses a template into an abstract syntax tree, which includes: the variable node, for example, ASTReference, etc., is used to indicate that the node is replaced with a corresponding variable value during the rendering process, for example, the variable of the getvariable value method is the variable name. When the template is analyzed, the new variable node is used for replacing the original implementation of Velocity, so that the enhancement and the expansion of the Velocity rendering function are realized.
Optionally, in another embodiment, on the basis of the above example, the embodiment may further include: before template rendering, collecting all business services by utilizing a dependent injection (Spring) container; and establishing a corresponding relation between the business service and the service name so as to find the corresponding business service according to the service name.
Wherein the collecting all the traffic services by using a dependent injection (Spring) container comprises: firstly, after the Spring container is initialized, traversing all service objects in the Spring container; then, determining whether the method has an annotation with a specific annotation identifier (e.g., Java language annotation such as @ ServiceId ("XXX")), if yes, determining that the method is a service method, and using the value of the annotation as a key (key) in the service factory; and finally, packaging the service method into a service result proxy object, and storing the service structure proxy object as a value into a service factory so as to search the service result proxy object according to a key in the service factory during template rendering.
That is to say, in this embodiment, before rendering the template, all the business services need to be collected in advance, and when an execution result of a certain service is needed, the corresponding service can be found according to the service name and the service can be executed, so as to obtain the execution result.
The service factory interface provided by the embodiment of the application is as follows:
Figure BDA0001079294370000101
in this embodiment, the implementation of the service factory can be set according to business needs. The following describes a very typical implementation of a service factory provided by the present application:
the collection of business services depends on a Spring container, after the Spring container is initialized, a method for traversing all service objects in the Spring container is traversed, if a method has an annotation with a specific annotation identifier, the method is considered to be a service method, then the value of the annotation is used as a key in a service factory, the service method is packaged into a service result proxy object, and the proxy object is used as a value to be stored in the service factory, so that the service result proxy object is searched according to the key in the service factory during template rendering. The use of a particular annotation identifier (e.g., Java language annotation such as @ ServiceId ("XXX")) is shown below:
Figure BDA0001079294370000102
Figure BDA0001079294370000111
where the value of a particular annotation identifier (e.g., Java language annotation such as @ ServiceId ("XXX")) corresponds to the method giving the service an individual name that is consistent with the variables used in the template. If the template is rendered by the method, the OfferService and the SerlerService do not need to be called in a Controller and the return result is put in a template rendering context object (context), and the method of the two services is directly and automatically called during template rendering. The template file content should be such that:
<html>
<body>
total $ { offselist service
The total number of sellers is $ { serllerListService
</body>
</html>
It can be seen that the variable names in the template directly correspond to the names of the annotations on the methods.
The service result proxy object is used for executing service according to the current request to obtain a final service result. The following is a typical implementation of a service result proxy object:
Figure BDA0001079294370000112
Figure BDA0001079294370000121
Figure BDA0001079294370000131
the design of the service result proxy class utilizes the current request object to execute the service on one hand, and caches the executed result in the request object on the other hand, so as to avoid repeatedly calling the service when the same service result proxy object is called again next time. When creating the service result proxy object, ifacemethodlnvoker and HttpServletRequest need to be passed in. Ifacemethoddlinvoker is actually the wrapper of the method of the service and http serverequest is the current request, because the execution of the method of the service depends on the current request object (http serverequest), such as: the number of goods should be different for searching different words, and the following business service execution will be described in detail.
It should be noted that there are two attributes in the CachedServiceResultProxy class: when the service is executed, only parameter information in the request (request object) needs to be injected into parameters of a service method (similar to a parameter binding function in a SpirngMVC, Struts and Webx open source framework, which is a common technology), namely, the service method can be executed in a java reflection mode to obtain a service execution result.
It should be noted that there are many existing MVC (a known web development model) frameworks, and spring MVC, Struts2, and Webx commonly used in ali are more popular. The method and the device for template rendering provided by the embodiment of the application can be directly applied to Java language and can also be applied to any other template rendering technology, such as: js, python, etc.
The template rendering method provided by the application can also be called a trigger template rendering method, namely, corresponding variable values do not need to be prepared for all variables in the template before the template is rendered, and when the template is rendered sequentially, corresponding service methods are executed by touching variable names and the execution return result of the service is used as the variable values, so that the code writing of a controller is reduced, and the execution efficiency of template rendering operation is improved.
Corresponding to the embodiment of the method for rendering the template, the application also provides an embodiment of a device for rendering the template.
The embodiment of the template rendering device provided by the application can be applied to equipment. The device embodiments may be implemented by software, or by hardware, or by a combination of hardware and software. The software implementation is taken as an example, and is formed by reading corresponding computer program instructions in a processor volatile memory of the device where the software implementation is located into an internal memory for operation as a logical device. From a hardware aspect, as shown in fig. 3, a hardware structure diagram of the stencil rendering apparatus 321 provided in this application is a hardware structure diagram, except for the processor 31, the memory 32, the network interface 33, and the nonvolatile memory 34 shown in fig. 3, a device where the apparatus is located in the embodiment may also include other hardware according to an actual function of the device, which is not described again.
Referring to fig. 4, a schematic structural diagram of an apparatus for template rendering according to an embodiment of the present application is shown, where the apparatus includes: an acquisition unit 41, a first determination unit 42, a first rendering unit 43, a generation unit 44 and a transmission unit 45, wherein,
an obtaining unit 41, configured to obtain a web browsing request of a user;
a first determining unit 42, configured to determine a template corresponding to the web browsing request;
a first rendering unit 43, configured to perform template rendering on the basis of the data returned by the template calling service;
a generating unit 44, configured to generate a corresponding web page according to a rendering result of the first rendering unit;
a sending unit 45, configured to return the web page to the user; that is, the web page is returned to the user browser, so that the browser converts the web page and displays the converted web page to the user.
Optionally, in another embodiment, the first rendering unit includes: a reading unit, a parsing unit, a first traversal unit, a first determining unit, a second rendering unit, a second determining unit, an executing unit and a second rendering unit (not shown), wherein,
a reading unit for reading the template;
the analysis unit is used for analyzing the read template into an abstract syntax tree;
the first traversal unit is used for traversing each node in the abstract syntax tree;
the first judging unit is used for judging whether a corresponding variable value is searched in the template rendering context object by using the variable name of the node when the first traversal unit traverses to one node;
a second rendering unit, configured to render the node using the variable value when the first determining unit determines that the corresponding variable value is found in the template rendering context object;
a second judging unit, configured to judge whether the corresponding service is found from a service factory by using the variable name when the first judging unit judges that the corresponding variable value is not found in the template rendering context object;
the executing unit is used for executing the business service when the second judging unit judges that the corresponding business service is found;
and the third rendering unit is used for rendering the node by taking the data of the business service executed by the execution unit as a variable value.
Optionally, in another embodiment, the abstract syntax tree obtained by parsing by the parsing unit includes variable nodes, where the variable nodes are used to indicate that the nodes are replaced with corresponding variable values in the rendering process.
Optionally, in another embodiment, the apparatus may further include: the collecting unit 51 and the establishing unit 52 are schematically shown in fig. 5, wherein,
a collecting unit 51, configured to collect all business services by using a dependent injection container before template rendering;
the establishing unit 52 is connected to the first rendering unit, and is configured to establish a corresponding relationship between the service and the service name, so as to find the corresponding service according to the service name.
Optionally, in another embodiment, the collecting unit includes: a second traversal unit, a third judgment unit, a second determination unit, a packing unit, and a storage unit (not shown), wherein,
the second traversal unit is used for traversing all the methods of the service objects in the dependence injection container after the dependence injection container is initialized;
a third judging unit, configured to judge whether there is an annotation identified by a specific annotation on the method;
a second determination unit configured to determine that the method is a service method and to use a value of an annotation as a key in a service factory when the third judgment unit judges that the annotation is present;
the packaging unit is used for packaging the service method into a service result proxy object;
and the storage unit is used for saving the service structure proxy object as a value to a service factory so as to search the service result proxy object according to a key in the service factory during template rendering.
The implementation process of the functions and actions of each unit in the above device is specifically described in the implementation process of the corresponding step in the above method, and is not described herein again.
In the embodiment of the application, before the template is rendered, corresponding variable values of all variables in the template do not need to be prepared, but when the template is rendered sequentially, the corresponding service method is executed after meeting the variable name, and the execution return result of the service is used as the variable value. Not only is the code writing of the controller reduced, but also the execution efficiency of the template rendering operation is improved.
Referring to fig. 6, a schematic structural diagram of a browser provided in an embodiment of the present application is shown, where the schematic structural diagram includes: a control module 61, a traffic handling module 62 and a template 63, wherein,
the control module 61 is configured to, when receiving a web page browsing request sent by a user 64, send a template selection request corresponding to the web page browsing request to the template 63;
the template 63 is configured to, when receiving the template selection request, select a template corresponding to the web browsing request, and send a service invocation request to the service processing module 62;
the service processing module 62 is configured to generate corresponding data according to the call request when receiving the call request, and return the data to the template 63; wherein the data comprises: the method comprises the steps that data of business services are directly obtained from a service factory in a template rendering process;
the template 63 is configured to receive data returned by the service processing module 62, perform template rendering according to the data, generate a corresponding web page, and return the web page to the user 64, where the data includes: and acquiring the data of the business service from the service factory in the template rendering process.
The control module 61 performs template rendering on the data returned by the service invoked based on the template, and generates a corresponding web page, which is detailed above and will not be described herein again.
For ease of understanding, the following description is given with specific examples.
Fig. 7 is a diagram illustrating an application example of template rendering provided in an embodiment of the present application. In fig. 7, taking the webx framework as an example, each page block has a template (View) and a Controller (Controller), where the Controller mainly assembles the business services of the business layer and then provides the assembled data to the template rendering. As can be seen from fig. 7, the engine data is required to be used in all of the breadcrumbs template, the navigation template, and the main data area template, so the Controller in all of the three templates needs to invoke the engine data service. By adopting the technical scheme of the application, the Controller does not need to assemble the business data for the template through the expansion of the rendering engine, but directly fills the business service data of the business layer into the template, so that the code compiling of the Controller can be greatly reduced, and the execution efficiency of the template rendering operation is also improved.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the application. One of ordinary skill in the art can understand and implement it without inventive effort.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.

Claims (8)

1. A method of stencil rendering, comprising:
acquiring a webpage browsing request of a user;
determining a template corresponding to the webpage browsing request;
and performing template rendering on data returned by calling the business service based on the template to generate a corresponding webpage, wherein the data comprises: acquiring data of the business service from a service factory in the template rendering process; the step of performing template rendering on the data returned by the business service based on the template call to generate a corresponding webpage comprises the following steps: reading the template, and analyzing the read template into an abstract syntax tree; traversing each node in the abstract syntax tree; when a node is traversed, searching a corresponding variable value in the template rendering context object by using the variable name of the node; if the corresponding variable value is found, rendering the node by using the variable value; if the corresponding variable value is not found, searching the corresponding business service from the service factory by using the variable name; if the corresponding business service is found, executing the business service, and rendering the node by taking the data for executing the business service as a variable value; generating a webpage after rendering each node in the abstract syntax tree;
and returning the webpage to the user.
2. The method of claim 1, wherein the abstract syntax tree includes variable nodes, and the variable nodes are used to indicate that the nodes are replaced with corresponding variable values during the rendering process.
3. The method of any of claims 1 to 2, further comprising:
before template rendering, collecting all business services by using a dependent injection container;
and establishing a corresponding relation between the business service and the service name so as to find the corresponding business service according to the service name.
4. The method of claim 3, wherein collecting all traffic services using a dependent injection container comprises:
traversing all service object methods in the dependent injection container after the dependent injection container is initialized;
judging whether the method has an annotation with a specific annotation identifier, if so, determining that the method is a service method, and using the value of the annotation as a key in a service factory;
and packaging the service method into a service result proxy object, and storing the service result proxy object as a value into a service factory so as to search the service result proxy object according to keys in the service factory during template rendering.
5. A stencil rendering apparatus, comprising:
the acquisition unit is used for acquiring a webpage browsing request of a user;
the first determining unit is used for determining a template corresponding to the webpage browsing request;
a first rendering unit, configured to perform template rendering on data returned by the template-based calling business service, where the data includes: the method comprises the steps that data of business services are directly obtained from a service factory in a template rendering process; the first rendering unit includes: a reading unit for reading the template; the analysis unit is used for analyzing the read template into an abstract syntax tree; the first traversal unit is used for traversing each node in the abstract syntax tree; the first judging unit is used for judging whether a corresponding variable value is searched in the template rendering context object by using the variable name of the node when the first traversal unit traverses to one node; a second rendering unit, configured to render the node using the variable value when the first determining unit determines that the corresponding variable value is found in the template rendering context object; a second judging unit, configured to judge whether the corresponding service is found from a service factory by using the variable name when the first judging unit judges that the corresponding variable value is not found in the template rendering context object; the executing unit is used for executing the business service when the second judging unit judges that the corresponding business service is found; a third rendering unit, configured to render the node using data of the business service executed by the execution unit as a variable value;
the generating unit is used for generating a corresponding webpage according to the rendering result of the first rendering unit;
and the sending unit is used for returning the webpage to the user.
6. The apparatus of claim 5, further comprising:
the collection unit is used for collecting all business services by utilizing a dependent injection container before template rendering;
and the establishing unit is used for establishing the corresponding relation between the business service and the service name so as to find the corresponding business service according to the service name.
7. The apparatus of claim 6, wherein the collection unit comprises:
the second traversal unit is used for traversing all the methods of the service objects in the dependence injection container after the dependence injection container is initialized;
a third judging unit, configured to judge whether there is an annotation identified by a specific annotation on the method;
a second determination unit configured to determine that the method is a service method and to use a value of an annotation as a key in a service factory when the third judgment unit judges that the annotation is present;
the packaging unit is used for packaging the service method into a service result proxy object;
and the storage unit is used for saving the service structure proxy object as a value to a service factory so as to search the service result proxy object according to a key in the service factory during template rendering.
8. A browser, comprising: a control module, a template module and a service processing module, wherein,
the control module is used for sending a template selection request corresponding to a webpage browsing request to the template when receiving the webpage browsing request sent by a user;
the template module is used for selecting a template corresponding to the webpage browsing request when the template selection request is received, and sending a calling request of business service to the business processing module;
the service processing module is used for generating corresponding data according to the call request when receiving the call request and returning the data to the template module; wherein the data comprises: the method comprises the steps that data of business services are directly obtained from a service factory in a template rendering process;
the template module is also used for receiving the data returned by the service processing module, performing template rendering according to the data, generating a corresponding webpage and returning the webpage to the user;
performing template rendering according to the data to generate a corresponding webpage, including: reading the template, and analyzing the read template into an abstract syntax tree; traversing each node in the abstract syntax tree; when a node is traversed, searching a corresponding variable value in the template rendering context object by using the variable name of the node; if the corresponding variable value is found, rendering the node by using the variable value; if the corresponding variable value is not found, searching the corresponding business service from the service factory by using the variable name; if the corresponding business service is found, executing the business service, and rendering the node by taking the data for executing the business service as a variable value; and generating a webpage after rendering each node in the abstract syntax tree.
CN201610671634.9A 2016-08-15 2016-08-15 Template rendering method and device and browser Active CN107766344B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610671634.9A CN107766344B (en) 2016-08-15 2016-08-15 Template rendering method and device and browser

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610671634.9A CN107766344B (en) 2016-08-15 2016-08-15 Template rendering method and device and browser

Publications (2)

Publication Number Publication Date
CN107766344A CN107766344A (en) 2018-03-06
CN107766344B true CN107766344B (en) 2021-07-30

Family

ID=61259862

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610671634.9A Active CN107766344B (en) 2016-08-15 2016-08-15 Template rendering method and device and browser

Country Status (1)

Country Link
CN (1) CN107766344B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108846877B (en) * 2018-06-06 2023-03-31 中国电子科技集团公司第二十九研究所 Comprehensive drawing method and system based on image classification result
CN109324798A (en) * 2018-09-14 2019-02-12 山东浪潮通软信息科技有限公司 A kind of implementation method of JIT Just-In-Time web form metadata
CN111104587A (en) * 2018-10-26 2020-05-05 北京金山云网络技术有限公司 Webpage display method and device and server
CN109635175B (en) * 2018-11-06 2021-12-31 北京字节跳动网络技术有限公司 Page data splicing method and device, readable storage medium and electronic equipment
CN110232178A (en) * 2019-05-29 2019-09-13 北京中亦安图科技股份有限公司 Report generation method and device
CN110263287A (en) * 2019-06-24 2019-09-20 北京字节跳动网络技术有限公司 Page rendering method and apparatus
CN112632941A (en) * 2019-09-23 2021-04-09 北京国双科技有限公司 Method, device, equipment and storage medium for generating PDF format public security document
CN111124528B (en) * 2019-11-11 2023-06-27 泰康保险集团股份有限公司 Page loading method and device, electronic equipment and computer readable storage medium
CN113867827A (en) * 2020-06-29 2021-12-31 北京字节跳动网络技术有限公司 Method and device for loading webpage

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101126979A (en) * 2007-06-08 2008-02-20 北京大学 Loose coupling access method by employing server public service
CN102902781A (en) * 2012-09-28 2013-01-30 五八有限公司 Method and device for webpage decoration and pushing
CN103164193A (en) * 2011-12-12 2013-06-19 阿里巴巴集团控股有限公司 Method and device for template rendering

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9208141B2 (en) * 2010-02-05 2015-12-08 Oracle International Corporation Generating and displaying active reports

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101126979A (en) * 2007-06-08 2008-02-20 北京大学 Loose coupling access method by employing server public service
CN103164193A (en) * 2011-12-12 2013-06-19 阿里巴巴集团控股有限公司 Method and device for template rendering
CN102902781A (en) * 2012-09-28 2013-01-30 五八有限公司 Method and device for webpage decoration and pushing

Also Published As

Publication number Publication date
CN107766344A (en) 2018-03-06

Similar Documents

Publication Publication Date Title
CN107766344B (en) Template rendering method and device and browser
US11150874B2 (en) API specification generation
JP5695027B2 (en) Method and system for acquiring AJAX web page content
CN107609135B (en) Page element determining method and device, and user behavior path determining method and device
US8131753B2 (en) Apparatus and method for accessing and indexing dynamic web pages
CN104063401B (en) The method and apparatus that a kind of webpage pattern address merges
CN102597993A (en) Managing application state information by means of a uniform resource identifier (uri)
CN101211364A (en) Method and system for social bookmarking of resources exposed in web pages
CN110222251B (en) Service packaging method based on webpage segmentation and search algorithm
CN108304410A (en) A kind of detection method, device and the data analysing method of the abnormal access page
CN102567400B (en) Method for realizing Web visit and Web server
CN105808701B (en) Realize the method and system communicated between list automatic Verification and multisystem
US10943063B1 (en) Apparatus and method to automate website user interface navigation
CN106126693A (en) The sending method of the related data of a kind of webpage and device
CN106294885A (en) A kind of data collection towards isomery webpage and mask method
Bellucci et al. Automatic reverse engineering of interactive dynamic web applications to support adaptation across platforms
CN105005596B (en) page display method and device
CN114237594A (en) Form interface generation method, device and system and readable storage medium
CN111881043B (en) Page testing method and device, storage medium and processor
US10095791B2 (en) Information search method and apparatus
CN105912573B (en) Data updating method and device
CN104268246A (en) Method for generating instruction script for visiting websites and visiting method and device
CN112035744A (en) Page recommendation method, device, equipment and storage medium
WO2014049308A1 (en) Documentation parser
CN104239452A (en) Method and device for resource acquisition

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 1251678

Country of ref document: HK

GR01 Patent grant
GR01 Patent grant