CN107766344A - The method, apparatus and browser that a kind of template renders - Google Patents

The method, apparatus and browser that a kind of template renders Download PDF

Info

Publication number
CN107766344A
CN107766344A CN201610671634.9A CN201610671634A CN107766344A CN 107766344 A CN107766344 A CN 107766344A CN 201610671634 A CN201610671634 A CN 201610671634A CN 107766344 A CN107766344 A CN 107766344A
Authority
CN
China
Prior art keywords
template
service
unit
business
data
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.)
Granted
Application number
CN201610671634.9A
Other languages
Chinese (zh)
Other versions
CN107766344B (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

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 method, apparatus and browser, methods described that a kind of template of the application offer renders include:Obtain the web page browsing request of user;Determine template corresponding to the web page browsing request;The data for calling business service to return based on the template carry out template and rendered, Webpage corresponding to generation, wherein, the data include:The data of the business service directly obtained in template render process from service Factory;The Webpage is returned to the user.In the embodiment of the present application, pass through the extension to rendering engine, establish the corresponding relation between template and business service, template renders can directly perform the data returned using business service, it need not be the assembling that template carries out business datum to make controller, but allow the service data of operation layer to be directly filled into the template of determination, the written in code of controller is so not only greatly reduced, and improve the execution efficiency of template Rendering operations.

Description

The method, apparatus and browser that a kind of template renders
Technical field
The application is related to network technique field, the method, apparatus and browser that more particularly to a kind of template renders.
Background technology
In recent years, with the development of web technology, might have tens page access amount daily, and quickly to Family shows merchandise news and shows that different merchandise news has become the primary hand of major website competition for different users Section.But due to the presence of magnanimity merchandise news, and need the variation of information shown.Before template renders, controller (Controller) need to call multiple application services to carry out rigging and render required all template datas, it is also desirable to Selection renders the page using which template, and then template data (Model) is filled into template by rendering engine, obtained most Whole page source code (html), finally, user browser is returned to by page source code.
During existing template renders, because Controller needs to call multiple business services to come needed for rigging renders Data, add the written in code of controller, reduce the execution efficiency of template Rendering operations.
The content of the invention
In view of this, the application provides method, apparatus and the browser that a kind of template renders, with solve in the prior art by Need to call multiple business services to carry out rigging in controller and render required data, add the written in code of controller, And the technical problem for causing the execution efficiency of template Rendering operations to reduce.
Specifically, the application is achieved by the following technical solution:
First aspect provides a kind of method that template renders, including:
Obtain the web page browsing request of user;
Determine template corresponding to the web page browsing request;
The data for calling business service to return based on the template carry out template and rendered, Webpage corresponding to generation, its In, the data include:The data of the business service directly obtained in template render process from service Factory;
The Webpage is returned to the user.
Optionally, the data for calling business service to return based on the template carry out template and rendered, webpage corresponding to generation The page includes:
Read the template;
The template of reading is resolved into abstract syntax tree;
Each node in ergodic abstract syntax tree;
When often traversing a node, searched and corresponded in template rendering context object using the variable name of the node Variate-value;
If finding corresponding variate-value, go to render the node using the variate-value;
If not finding corresponding variate-value, using the variable name searched from service Factory corresponding to business Service;
If finding corresponding business service, the business service is performed, and the number for performing the business service The node is rendered according to as variate-value;
After rendering each node in the abstract syntax tree, Webpage is generated.
Optionally, the abstract syntax tree includes variable node, and the variable node is used for representing the node in wash with watercolours Corresponding variate-value can be replaced by during dye.
Optionally, in addition to:
Before template renders, the business service all using injection container collection is relied on;
The corresponding relation established between the business service and Service name, in order to be found correspondingly according to the Service name Business service.
Optionally, the business service all using injection container collection is relied on, including:
After injection container initialization is relied on, the method for all service objects in traversal dependence injection container;
Judge whether there is the specific note for explaining mark in methods described, if, it is determined that methods described is exactly one Individual method of servicing, and using the value of note as the key in service Factory;
The method of servicing is packaged as a service result agent object, using the service result agent object as value It is saved in service Factory, key when being rendered in order to template in service Factory searches service result agent object.
Second aspect provides a kind of template rendering device, including:
Acquiring unit, the web page browsing for obtaining user are asked;
First determining unit, for determining template corresponding to the web page browsing request;
First rendering unit, the data for calling business service to return based on the template carry out template and rendered, wherein, The data include:The data of the business service directly obtained in template render process from service Factory;
Generation unit, for the Webpage according to corresponding to the generation of the rendering result of first rendering unit;
Transmitting element, for returning to the Webpage to the user.
Optionally, the rendering unit includes:
Reading unit, for reading the template;
Resolution unit, for the template of reading to be resolved into abstract syntax tree;
First Traversal Unit, for each node in ergodic abstract syntax tree;
First judging unit, for when first Traversal Unit often traverses a node, judging to utilize the section Whether the variable name of point searches corresponding variate-value in template rendering context object;
Second rendering unit, for judging to search in the template rendering context object in first judging unit During to corresponding variate-value, go to render the node using the variate-value;
Second judging unit, for judging do not have in the template rendering context object in first judging unit Corresponding to finding during variate-value, judge whether corresponding business service is found from service Factory using the variable name;
Execution unit, for when second judging unit judges to find corresponding business service, performing the industry Business service;
3rd rendering unit, for being rendered using the data of the execution unit execution business service as variate-value The node.
Optionally, in addition to:
Collector unit, for before template renders, injecting all business services of container collection using relying on;
Unit is established, for establishing the corresponding relation between the business service and Service name, in order to according to the clothes Business name finds corresponding business service.
Optionally, the collector unit includes:
Second Traversal Unit, for after injection container initialization is relied on, traversal to rely on all services pair in injection container The method of elephant;
3rd judging unit, for judging whether there is the specific note for explaining mark in methods described;
Second determining unit, for judging that it is service side to determine methods described when having note in the 3rd judging unit Method, and using the value of note as the key in service Factory;
Packaging unit, for the method for servicing to be packaged as into a service result agent object;
Memory cell, for the service structure agent object to be saved in service Factory as value, in order to template Key when rendering in service Factory searches service result agent object.
The third aspect provides a kind of browser, including:Control module, template and Service Processing Module, wherein,
The control module, for receive user transmission web page browsing request when, to the template send and institute State stencil-chosen request corresponding to web page browsing request;
The template, for when receiving the stencil-chosen request, selecting corresponding with web page browsing request Template, and to the Service Processing Module send business service call request;
The Service Processing Module, for when receiving the call request, being generated according to the call request corresponding Data, and the data are returned into the template;Wherein, the data include:Directly from service in template render process The data of the business service obtained in factory;
The template, the data returned for receiving the Service Processing Module, and carry out template wash with watercolours according to the data Dye, Webpage corresponding to generation, and return to the Webpage to the user.
In the embodiment of the present application, by the extension to rendering engine, the corresponding pass between template and business service is established System, template renders can directly perform the data returned using business service, and it need not be that template carries out business number to make controller According to assembling, but allow the service data of operation layer to be directly filled into the template of determination, so not only greatly reduce controller Written in code, and improve the execution efficiency of template Rendering operations.
It should be appreciated that the general description and following detailed description of the above are only exemplary and explanatory, not The application can be limited.
Brief description of the drawings
Fig. 1 is the flow chart for the method that a kind of template that the embodiment of the present application provides renders;
Fig. 2 is the flow chart that a kind of template that the embodiment of the present application provides renders specific implementation process;
Fig. 3 is a kind of hardware structure diagram of equipment where the device that the template that the embodiment of the present application provides renders;
Fig. 4 is the structural representation for the device that a kind of template that the embodiment of the present application provides renders;
Fig. 5 is another structural representation for the device that a kind of template that the embodiment of the present application provides renders;
Fig. 6 is a kind of structural representation of the template rendering apparatus provided in the embodiment of the present application;
Fig. 7 is a kind of application schematic diagram of the webx frameworks provided in the embodiment of the present application.
Embodiment
Here exemplary embodiment will be illustrated in detail, its example is illustrated in the accompanying drawings.Following description is related to During accompanying drawing, unless otherwise indicated, the same numbers in different accompanying drawings represent same or analogous key element.Following exemplary embodiment Described in embodiment do not represent all embodiments consistent with the application.On the contrary, they be only with it is such as appended The example of the consistent apparatus and method of some aspects be described in detail in claims, the application.
It is only merely for the purpose of description specific embodiment in term used in this application, and is not intended to be limiting the application. " one kind " of singulative used in the application and appended claims, " described " and "the" are also intended to including majority Form, unless context clearly shows that other implications.It is also understood that term "and/or" used herein refers to and wrapped Containing the associated list items purpose of one or more, any or all may be combined.
It will be appreciated that though various information, but this may be described using term first, second, third, etc. in the application A little information should not necessarily be limited by these terms.These terms are only used for same type of information being distinguished from each other out.For example, do not departing from In the case of the application scope, the first information can also be referred to as the second information, and similarly, the second information can also be referred to as One information.Depending on linguistic context, word as used in this " if " can be construed to " ... when " or " when ... When " or " in response to determining ".
Referring to Fig. 1, it is the flow chart of method that a kind of template that the embodiment of the present application provides renders;In the embodiment, With WEB development modes, i.e., exemplified by MVC pattern, methods described includes:
Step 101:Obtain the web page browsing request of user;
Service platform receives the web page browsing request of user, and generally carries the system that user specifies in web page browsing request One URLs (URL, Uniform Resource Locator, also known as web page address):Service in the embodiment is put down Platform, can be controller (Controller) in server or controller, such as MVC pattern etc..
Step 102:Determine template corresponding to the web page browsing request;
In the step, service platform can be asked according to web page browsing in carrying URL come template corresponding to determining, its In, template, can be Velocity templates etc. by taking Java language as an example.
Step 103:The data for calling business service to return based on the template carry out template and rendered, webpage corresponding to generation The page;
In the embodiment, it is as follows that a kind of template renders specific implementation process:Template is resolvable to abstract syntax tree, by time Go through and render each node in abstract syntax tree to complete rendering for full page.During traversal, a node is often encountered, With regard to being searched with the variable name of this node in template rendering context object (context), if it is found, just using variate-value Go to render this node.This is the way of general template rendering engine, and the application is the base in the template rendering engine of routine Certain extension is carried out on plinth, i.e., if not finding the variable name of the node in context, just with the variable name of the node Business service corresponding to being searched from service Factory;If finding business service, the business service is carried out, and business will be performed The returned data of service renders this node as variate-value.Finally, each node in the abstract syntax tree renders Afterwards, Webpage is generated., wherein it is desired to illustrate, the Webpage in the present embodiment is html source codes.
The specific implementation process of the step refers to Fig. 2, will not be repeated here.
Step 104:The Webpage is returned to the user.
Also just say, the Webpage is returned to the user browser, in order to which the browser turns to Webpage The user is shown to after changing.
In the embodiment, because the page obtained after rendering is html source codes, the html source codes only pass through browser User can be shown to, therefore, it is necessary to which the html source codes first are returned into user browser, browser is shown by the page of conversion Give the user.
In the embodiment of the present application, by the extension to rendering engine, the corresponding pass between template and business service is established System, template renders can directly perform the data returned using business service, and it need not be that template enters industry to make Controller The assembling for data of being engaged in, but allow the business service data of operation layer to be directly filled into the template of determination, so not only subtract significantly Few Controller written in code, and improve the execution efficiency of template Rendering operations.
Also referring to Fig. 2, a kind of flow chart of the template render process provided for the embodiment of the present application, in the embodiment, By service platform by taking controller as an example, specifically include:
Step 201:Read the template;
Step 202:The template of reading is resolved into abstract syntax tree;
Step 203:Each node in ergodic abstract syntax tree;
Step 204:Judge the node type of each node traversed, if variable, then perform step 205;Such as Fruit is text data, performs step 210;
Step 205:Judge whether the variable name of the node is searched pair in template rendering context object (context) The variate-value answered;If found, step 206 is performed;Otherwise, step 207 is performed;
Step 206:Go to render the node using the variate-value, render end afterwards;
Step 207:Judge corresponding business service whether is searched from service Factory using the variable name;If search Arrive, perform step 208;Otherwise, step 209 is performed;
Step 208:Perform the business service, and using performing the data of the business service as variate-value to render State node;
Step 209:Render exception;
Step 210;Go to render the node using the text data;
Step 211:After rendering each node in the abstract syntax tree, Webpage is generated.
That is, in the embodiment, template is resolvable to abstract syntax tree, is rendered by traversal in abstract syntax tree Each node renders to complete full page.During traversal, a node is often encountered, just existed with the variable name of this node Searched in template rendering context object (context), if it is found, just being gone to render this node with variate-value.This is one As template rendering engine way, be to have carried out one on the basis of the template rendering engine of routine and in the embodiment of the present application Fixed extension, i.e., if not finding the variable name in template rendering context object (context), variable name is just used from service Business service corresponding to being searched in factory;If finding business service, the business service is carried out, the return number of business service This node is rendered according to as variate-value.With velocity rendering engines, (for example a template of increasing income of Java language renders Engine) exemplified by, the implementation that amended trigger-type template renders is as follows:
There is aforesaid way to understand that template can be parsed into abstract syntax tree by Velocity, and the abstract syntax tree includes:Become Node is measured, such as, ASTReference etc., corresponding to variable node is used for representing that the node can be replaced by render process Variate-value, for example the parameter variable of getVariableValue methods is exactly variable name.The embodiment of the present application is in parsing mould During plate, the realization for replacing original Velocity is realized with this new variable node, to realize that velocity renders function Enhancing and extension.
Optionally, in another embodiment, the embodiment can also include on the basis of examples detailed above:In template wash with watercolours Before dye, the business service all using injection (Spring) container collection is relied on;Establish between the business service and Service name Corresponding relation, in order to find corresponding business service according to the Service name.
Wherein, the business service all using injection (Spring) container collection is relied on, including:First hold in Spring After device initialization, the method for all service objects in traversal Spring containers;Then, judge whether have in methods described specifically Note mark (such as:Java language explains of this sort ServiceId (" XXX ")) note, if, it is determined that it is described Method is exactly a method of servicing, and using the value of note as the key (key) in service Factory;Finally, by the method for servicing A service result agent object is packaged as, the service structure agent object is saved in service Factory as value, so as to Key (key) when template renders in service Factory searches service result agent object.
That is, in the embodiment, it is necessary to gather all business services in advance before template is rendered, when need When wanting the implementing result of some service, it can be serviced according to corresponding to being found service name and perform service, obtain implementing result.
The interface for the service Factory that the embodiment of the present application provides is as follows:
In the embodiment, the realization of service Factory can be set according to business needs.The application is described below to carry A kind of implementation process of the very typical service Factory supplied:
The collection of business service depends on Spring containers, after the initialization of Spring containers, travels through in Spring containers The method of all service objects, if there is the specific note for explaining mark in method, then it is assumed that this method is exactly one Method of servicing, then by the use of the value explained as the key in service Factory, method of servicing is packaged as a service result agency couple As, be saved in by the use of this agent object as value in service Factory, key when being rendered in order to template in service Factory come Search service result agent object.Wherein, it is specific explain mark (such as:Java language explains of this sort@ServiceId (" XXX ")) usage it is as follows:
Wherein, it is specific explain mark (such as:Java language explains of this sort@ServiceId (" XXX ")) value phase When then giving the method for service to take alias, it is consistent with the variable used in template.If with the mode of the application To render template, then OfferService and SellerService and handle need not be called in Controller (controller) Returning result is put into template rendering context object (context), directly calls above two to take when template renders automatically The method of business.Template file content should be such:
<html>
<body>
A total of $ of commodity { offerListService.count } is individual
A total of $ of seller { serllerListService.size } is individual
</body>
</html>
It can be seen that variable name is directly corresponding with the title of the note in method in template.
The effect of service result agent object is to perform service according to current request, obtains final service result.Below It is a kind of realization of typical service result agent object:
The design of the service result proxy class, service on the one hand is performed using current request (request) object, separately On the one hand by the result cache of execution into request objects, in case next time calls same service result agent object again Shi Chongfu calls service.When creating service result agent object, it is necessary to incoming IFaceMethodInvoker and HttpServletRequest.IFaceMethodInvoker is exactly the packaging of the method serviced in fact, HttpServletRequest is exactly current request, because the execution of method of servicing depends on current request object (HttpServletRequest), such as:Different words are searched for, the number of commodity should be different, the business service behind this Execution can be discussed in detail.
It should be noted that there are two attributes in CachedServiceResultProxy classes: IFaceMethodInvoker serviceInvoker and HttpServletRequest request, during service execution, only need The parameter information in request (request object), in the parameter for the method for being injected into service (similar SpirngMVC, Wire Parameters function in Struts, Webx Open Framework, this is a kind of common technology), you can pass through java reflection modes Method of servicing is performed, obtains service execution result.
It should be noted that a kind of present MVC (known web development modes) framework has a lot, popular has Webx that SpringMVC, Struts2 and Ali commonly use etc..The method and apparatus that the template that the embodiment of the present application provides renders are not But Java language can be directly applied for, can be applicable to other any template Renderings, such as:javascript、 Node.js, python etc..
The method that the template that the application provides renders, is referred to as the method that trigger-type renders masterplate, that is, renders template Preceding need not be that all variables in template prepare its corresponding variate-value, but when masterplate order renders, encounter variable name Just go to perform corresponding method of servicing and using the execution returning result of service as variate-value, the code for reducing controller is compiled Write, improve the execution efficiency of template Rendering operations.
It is corresponding with the embodiment for the method that foregoing template renders, the implementation of the device rendered present invention also provides template Example.
The embodiment for the device that the template that the application provides renders can be applied in equipment.Device embodiment can pass through Software is realized, can also be realized by way of hardware or software and hardware combining.Exemplified by implemented in software, anticipated as a logic Device in justice, it is in corresponding computer program instructions are read in the processor volatile memory by equipment where it Deposit what middle operation was formed.For hardware view, as shown in figure 3, being the standby one kind of the template rendering device 321 of the application offer Hardware structure diagram, in addition to the processor 31 shown in Fig. 3, internal memory 32, network interface 33 and nonvolatile memory 34, Equipment in embodiment where device can also include other hardware, this is no longer gone to live in the household of one's in-laws on getting married generally according to the actual functional capability of the equipment State.
Fig. 4 is refer to, the structural representation for the device that a kind of template provided for the embodiment of the present application renders, described device Including:Acquiring unit 41, the first determining unit 42, the first rendering unit 43, generation unit 44 and transmitting element 45, wherein,
Acquiring unit 41, the web page browsing for obtaining user are asked;
First determining unit 42, for determining template corresponding to the web page browsing request;
First rendering unit 43, the data for calling business service to return based on the template carry out template and rendered;
Generation unit 44, for the Webpage according to corresponding to the generation of the rendering result of first rendering unit;
Transmitting element 45, for returning to the Webpage to the user;That is, return to institute to user browser Webpage is stated, the user is shown to after being changed in order to the browser to Webpage.
Optionally, in another embodiment, first rendering unit includes:Reading unit, resolution unit, the first traversal Unit, the first judging unit, the second rendering unit, the second judging unit, execution unit and the second rendering unit (not shown), Wherein,
Reading unit, for reading the template;
Resolution unit, for the template of reading to be resolved into abstract syntax tree;
First Traversal Unit, for each node in ergodic abstract syntax tree;
First judging unit, for when first Traversal Unit often traverses a node, judging to utilize the section Whether the variable name of point searches corresponding variate-value in template rendering context object;
Second rendering unit, for judging to search in the template rendering context object in first judging unit During to corresponding variate-value, go to render the node using the variate-value;
Second judging unit, for judging do not have in the template rendering context object in first judging unit Corresponding to finding during variate-value, judge whether corresponding business service is found from service Factory using the variable name;
Execution unit, for when second judging unit judges to find corresponding business service, performing the industry Business service;
3rd rendering unit, for being rendered using the data of the execution unit execution business service as variate-value The node.
Optionally, in another embodiment, the abstract syntax tree that the resolution unit parses to obtain includes variable node, The variable node is used for representing that the node can be replaced by corresponding variate-value in render process.
Optionally, in another embodiment, described device can also include:Collector unit 51 and unit 52 is established, it is tied Structure schematic diagram as shown in figure 5, wherein,
Collector unit 51, for before template renders, injecting all business services of container collection using relying on;
Unit 52 is established, is connected with the first rendering unit, it is corresponding between the business service and Service name for establishing Relation, in order to find corresponding business service according to the Service name.
Optionally, in another embodiment, the collector unit includes:Second Traversal Unit, the 3rd judging unit, second Determining unit, packaging unit and memory cell (not shown), wherein,
Second Traversal Unit, for after injection container initialization is relied on, traversal to rely on all services pair in injection container The method of elephant;
3rd judging unit, for judging whether there is the specific note for explaining mark in methods described;
Second determining unit, for judging that it is service side to determine methods described when having note in the 3rd judging unit Method, and using the value of note as the key in service Factory;
Packaging unit, for the method for servicing to be packaged as into a service result agent object;
Memory cell, for the service structure agent object to be saved in service Factory as value, in order to template Key when rendering in service Factory searches service result agent object.
The function of unit and the implementation process of effect specifically refer to and step are corresponded in the above method in said apparatus Implementation process, it will not be repeated here.
In the embodiment of the present application, its corresponding variate-value need not be prepared for all variables in template before rendering template, But when masterplate order renders, encounter variable name and just go to perform corresponding method of servicing and made with the execution returning result of service For variate-value.The written in code of controller is not only reduced, also improves the execution efficiency of template Rendering operations.
Also referring to Fig. 6, being a kind of structural representation of the browser provided in the embodiment of the present application, as illustrated, bag Include:Control module 61, Service Processing Module 62 and template 63, wherein,
The control module 61, for when receiving the web page browsing request of the transmission of user 64, being sent out to the template 63 Stencil-chosen corresponding with web page browsing request is sent to ask;
The template 63, for when receiving the stencil-chosen request, selecting corresponding with web page browsing request Template, and to the Service Processing Module 62 send business service call request;
The Service Processing Module 62, for when receiving the call request, according to call request generation pair The data answered, and the data are returned into the template 63;Wherein, the data include:In template render process directly from The data of the business service obtained in service Factory;
The template 63, the data returned for receiving the Service Processing Module 62, and carry out mould according to the data Plate renders, Webpage corresponding to generation, and returns to the Webpage to the user 64, wherein, the data include:Mould The data of the business service obtained in plate render process from service Factory.
Wherein, control module 61 is rendered based on the data progress template that the template calls business service to return, generation pair The Webpage answered specifically refers to above-mentioned, will not be repeated here.
In order to make it easy to understand, illustrated below with specific example.
As shown in fig. 7, the application exemplary plot that a kind of template to be provided in the embodiment of the present application renders.Fig. 7 is with webx frames Exemplified by frame, the block of each page has a template (View) and controller (Controller), here Controller Mainly the business service of operation layer is assembled, is then supplied to template to render the data after assembling.Can be with from Fig. 7 Find out, be required for using engine data in crumbs template, navigation template, main data area template, so in these three templates Controller is required for calling engine data service.If using the technical scheme of above-mentioned the application, by rendering engine Extension, it need not be the assembling that template carries out business datum to make Controller, but allows the business service data of operation layer It is directly filled into template, can so greatly reduces Controller written in code, also improves template Rendering operations Execution efficiency.
For device embodiment, because it corresponds essentially to embodiment of the method, so related part is real referring to method Apply the part explanation of example.Device embodiment described above is only schematical, wherein described be used as separating component The unit of explanation can be or may not be physically separate, can be as the part that unit is shown or can also It is not physical location, you can with positioned at a place, or can also be distributed on multiple NEs.Can be according to reality Need to select some or all of module therein to realize the purpose of application scheme.Those of ordinary skill in the art are not paying In the case of going out creative work, you can to understand and implement.
The preferred embodiment of the application is the foregoing is only, not limiting the application, all essences in the application God any modification, equivalent substitution and improvements done etc., should be included within the scope of the application protection with principle.

Claims (10)

1. a kind of method that template renders, it is characterised in that including:
Obtain the web page browsing request of user;
Determine template corresponding to the web page browsing request;
The data for calling business service to return based on the template carry out template and rendered, Webpage corresponding to generation, wherein, institute Stating data includes:The data of the business service obtained in template render process from service Factory;
The Webpage is returned to the user.
2. according to the method for claim 1, it is characterised in that the data for calling business service to return based on the template are entered Row template renders, and Webpage includes corresponding to generation:
Read the template;
The template of reading is resolved into abstract syntax tree;
Each node in ergodic abstract syntax tree;
When often traversing a node, corresponding change is searched in template rendering context object using the variable name of the node Value;
If finding corresponding variate-value, go to render the node using the variate-value;
If not finding corresponding variate-value, using the variable name is searched from service Factory corresponding to business take Business;
If finding corresponding business service, the business service is performed, and the data for performing the business service are made The node is rendered for variate-value;
After rendering each node in the abstract syntax tree, Webpage is generated.
3. according to the method for claim 2, it is characterised in that the abstract syntax tree includes variable node, the change Amount node is used for representing that the node can be replaced by corresponding variate-value in render process.
4. according to the method described in any one of claims 1 to 3, it is characterised in that also include:
Before template renders, the business service all using injection container collection is relied on;
The corresponding relation established between the business service and Service name, in order to find corresponding industry according to the Service name Business service.
5. according to the method for claim 4, it is characterised in that the business clothes all using injection container collection is relied on Business, including:
After injection container initialization is relied on, the method for all service objects in traversal dependence injection container;
Judge whether there is the specific note for explaining mark in methods described, if, it is determined that methods described is exactly a clothes Business method, and using the value of note as the key in service Factory;
The method of servicing is packaged as a service result agent object, preserved the service result agent object as value Into service Factory, key when being rendered in order to template in service Factory searches service result agent object.
A kind of 6. template rendering device, it is characterised in that including:
Acquiring unit, the web page browsing for obtaining user are asked;
First determining unit, for determining template corresponding to the web page browsing request;
First rendering unit, the data for calling business service to return based on the template carry out template and rendered, wherein, it is described Data include:The data of the business service directly obtained in template render process from service Factory;
Generation unit, for the Webpage according to corresponding to the generation of the rendering result of first rendering unit;
Transmitting element, for returning to the Webpage to the user.
7. device according to claim 6, it is characterised in that the rendering unit includes:
Reading unit, for reading the template;
Resolution unit, for the template of reading to be resolved into abstract syntax tree;
First Traversal Unit, for each node in ergodic abstract syntax tree;
First judging unit, for when first Traversal Unit often traverses a node, judging to utilize the node Whether variable name searches corresponding variate-value in template rendering context object;
Second rendering unit, for judging to find in the template rendering context object pair in first judging unit During the variate-value answered, go to render the node using the variate-value;
Second judging unit, for judging not search in the template rendering context object in first judging unit During to corresponding variate-value, judge whether corresponding business service is found from service Factory using the variable name;
Execution unit, for when second judging unit judges to find corresponding business service, performing the business clothes Business;
3rd rendering unit, the data for the execution unit to be performed to the business service are described to render as variate-value Node.
8. according to the device described in any one of claim 6 to 7, it is characterised in that also include:
Collector unit, for before template renders, injecting all business services of container collection using relying on;
Unit is established, for establishing the corresponding relation between the business service and Service name, in order to according to the Service name Find corresponding business service.
9. device according to claim 8, it is characterised in that the collector unit includes:
Second Traversal Unit, for after injection container initialization is relied on, traversal to rely on all service objects in injection container Method;
3rd judging unit, for judging whether there is the specific note for explaining mark in methods described;
Second determining unit, for judging that it is method of servicing to determine methods described when having note in the 3rd judging unit, and Using the value of note as the key in service Factory;
Packaging unit, for the method for servicing to be packaged as into a service result agent object;
Memory cell, for the service structure agent object to be saved in service Factory as value, in order to which template renders When key in service Factory search service result agent object.
10. a kind of browser, its particularly in, including:Control module, template and Service Processing Module, wherein,
The control module, for when receiving the web page browsing request of user's transmission, being sent and the net to the template Stencil-chosen request corresponding to page browsing request;
The template, for when receiving stencil-chosen request, selection and the corresponding template of web page browsing request, And the call request of business service is sent to the Service Processing Module;
The Service Processing Module, for when receiving the call request, being counted according to corresponding to call request generation According to, and the data are returned into the template;Wherein, the data include:Directly from service Factory in template render process The data of the business service of middle acquisition;
The template, it is additionally operable to receive the data that the Service Processing Module returns, and carries out template according to the data and render, Webpage corresponding to generation, and return to the Webpage to the user.
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 true CN107766344A (en) 2018-03-06
CN107766344B 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)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108846877A (en) * 2018-06-06 2018-11-20 中国电子科技集团公司第二十九研究所 A kind of composite mapping 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
CN109635175A (en) * 2018-11-06 2019-04-16 北京字节跳动网络技术有限公司 Page data joining method, device, readable storage medium storing program for executing 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
CN111104587A (en) * 2018-10-26 2020-05-05 北京金山云网络技术有限公司 Webpage display method and device and server
CN111124528A (en) * 2019-11-11 2020-05-08 泰康保险集团股份有限公司 Page loading method and device, electronic equipment and computer readable storage medium
CN112632941A (en) * 2019-09-23 2021-04-09 北京国双科技有限公司 Method, device, equipment and storage medium for generating PDF format public security document
CN113867827A (en) * 2020-06-29 2021-12-31 北京字节跳动网络技术有限公司 Method and device for loading webpage

Citations (4)

* 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
US20160048480A1 (en) * 2010-02-05 2016-02-18 Oracle International Corporation Generating and displaying active reports

Patent Citations (4)

* 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
US20160048480A1 (en) * 2010-02-05 2016-02-18 Oracle International Corporation Generating and displaying active reports
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

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108846877A (en) * 2018-06-06 2018-11-20 中国电子科技集团公司第二十九研究所 A kind of composite mapping method and system based on image classification result
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
CN109635175A (en) * 2018-11-06 2019-04-16 北京字节跳动网络技术有限公司 Page data joining method, device, readable storage medium storing program for executing and electronic equipment
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
CN111124528A (en) * 2019-11-11 2020-05-08 泰康保险集团股份有限公司 Page loading method and device, electronic equipment and computer readable storage medium
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

Also Published As

Publication number Publication date
CN107766344B (en) 2021-07-30

Similar Documents

Publication Publication Date Title
CN107766344A (en) The method, apparatus and browser that a kind of template renders
CN101211364B (en) Method and system for social bookmarking of resources exposed in web pages
CN102789484B (en) A kind of Web information processing method and apparatus
JP6744480B2 (en) Network-based ad data traffic latency reduction
CN105956161A (en) Information recommendation method and apparatus
CN104112002B (en) A kind of methods, devices and systems of list adaptation
CN102968341B (en) The method and apparatus of different editions IE kernels based on many kernel browsers switching
CN109726098A (en) Interface test method, device and computer readable storage medium
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
CN107766532A (en) A kind of front end Node.js automates positive static method
CN102075570A (en) Method for implementing HTTP (hyper text transport protocol) message caching mechanism based on keywords
CN106453216A (en) Malicious website interception method, malicious website interception device and client
CN107229760B (en) Storage medium, electronic device, the display methods of web page contents and device
CN106503111B (en) Webpage code-transferring method, device and client terminal
CN106126693A (en) The sending method of the related data of a kind of webpage and device
CN107203470B (en) Page adjustment method and device
CN104063407A (en) Browser architecture based on cloud computing and analysis method
CN112417338B (en) Page adaptation method, system and equipment
CN102222108B (en) Scripting method and device
CN103207877B (en) Coding/decoding method and device
CN108595457A (en) A kind of rendering intent and device of the waterfall stream page
CN104182402A (en) Browser interface address bar input control method and browser interface address bar input control system
CN105354269B (en) Web applicational language Localization methodologies and system based on reverse proxy and information filtering
CN104881453B (en) A kind of method and apparatus identifying type of webpage

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