One of the tools of web development technology--BEETL use notes

Source: Internet
Author: User

A , Introduction

Beetl, is a Bee Template Language abbreviation, it is not simply another template engine, but a new generation of template engine, it is powerful, good performance.

B , Advantages

for web applications, a controller must be used to render the template,and Beetl can also finish writing the template after the controller Case, the direct render template This method can be used either as a normal full-stack developer or as a standalone development template for front-end personnel.

Beetl is easy to integrate with other technical frameworks, and Webrender is provided by default to help with web integration development, all built-in integrations are based on this approach. If you think that the Beetl built-in Web Framework integration functionality is not enough, you can inherit this class, or refer to this kind of source code re-write.

relative to other Java template engine with full-featured, intuitive syntax , features such as high performance and easy maintenance of the prepared templates. Make it a good experience to develop and maintain templates. is a new generation of template engines. In a sense, it has the following characteristics:

complete function: with the mainstream Java compared to the template engine, Beetl have most of the functionality. Beetl itself has many unique features to complete the template authoring and maintenance, which other template engines do not have.

very simple: similar Javascript Grammar and custom, as long as half an hour can be half-learning and half guessing the full mastery of usage. Rejecting other template engines that non-human syntax and customs. It also supports HTML tags, making it easier to develop CMS Systems

Ultra-high performance: Beetl far more than the mainstream Java Template engine Performance ( engine performance 5-6 times and freemaker,2 times the JSP ), and consumes a lower CPU

Easy Integration: Beetl can be easily with a variety of Web framework integration, such as Springmvc , Jfinal,struts,nutz , jodd , Servlet and so on.

support templates are developed and tested separately, MVC schema, even if no M and the C section, you can also develop and test templates.

Expand and Personalize: Beetl support for custom methods, formatting functions, virtual properties, tags, and HTML label . also Beetl custom placeholders and control statement start symbols are also supported, and the user can fully create a toolkit that suits them.

The framework itself features:

1. custom placeholders and control statement start symbols, which help reduce template syntax for the pour-out of templates, such as in HTML templates, if the definition control statement symbol is <!--: and -->, Then, most template files can be opened with the browser. Some users only use a single symbol @ and a carriage return as the starting symbol of the control statement, which can improve the development efficiency

2. templates that can be tested individually. Without a real control layer and model layer,beetl templates can be developed and tested independently

3. support for looser MVC and strict MVC, if you embed the expression in the template language, complex conditional expressions, And the function calls are suspected of interfering with the business logic, you can prohibit the use of these grammars.

4. Strong safety output, through the safe output symbol! , can be in template variable, variable attribute reference, for loop, placeholder output,try-catch Medium Each place provides safe output, guarantee render normal

5. Template variables: Run a portion of the template output like js To assign a variable, and later processing. Use template variables to accomplish very complex page layouts (simple layouts can use the layout label function )

6. type speculation, can be at run time to speculate on the template variable type, to optimize performance, can also be shown by the method of annotation template variable properties (this is not necessary, but to help the IDE automatically prompt function)

7. pluggable design, error message hint, template engine caching mechanism, template resource management, local call security Manager , strict MVC restriction, The template engine itself has a default implementation, but can be fully customized to suit specific needs

8. enhanced syntax, such as for-elsefor,select-case, safe output symbols ! and so on, these grammars are especially suitable for template development

9. Ultra-high performance , with the fastest template interpretation engine, at the same time, there is a lower CPU consumption. 5-6 times the domestic use of freemaker. Suitable for a variety of template applications, such as code generation tools,CMS system, ordinary website, ultra-high traffic portal system, and rich client JS Framework Integrated background management application

C , processing processes

1 , the first user sends the request (Htmlfilter), the front-end controller receives the request not to carry on the processing, but entrusts to the other parser to handle, as the unified access point, carries on the global flow control;

2 , Htmlfilter (Simplecrossfilter), directly invokes the Dofilter method in Simplecrossfilter to process the request template (mainly loading the defined pseudo-data model, defined/webroot/values/ Common.html.var and the corresponding var file);

3 , the pseudo-data model of loading definition is stored in the session;

4 , renders the data in the session to the specified template (i.e. rendered through Webrender)

D , development configuration process

1 , in Web. XML the request interception Processor (listener) is configured in

          <filter>              <description></description>              <display-name>HTMLFilter</display-name>              <filter-name>htmlfilter </filter-name>             < filter-class>org.beetl.sample.htmlfilter</filter-class>          </filter>         <filter-mapping>              <filter-name>htmlfilter</ Filter-name>             <url-pattern >*.html</url-pattern>         </filter-mapping> 


2 , implementing the configured filtering Method (listener)

package org.beetl.sample; import java.io.ioexception; import javax.servlet.filter; import javax.servlet.filterchain;import javax.servlet.filterconfig;import  javax.servlet.servletexception;import javax.servlet.servletrequest;import  javax.servlet.servletresponse; import org.beetl.core.grouptemplate;import  org.beetl.ext.servlet.servletgrouptemplate;import org.beetl.ext.web.simplecrossfilter; /** *  Servlet Filter implementation classHTMLFilter */publicclass HTMLFilter  extends simplecrossfilter implements filter {            @Override          public void init ( FILTERCONFIG&NBSP;ARG0) throws servletexception {                                                 }                   public void dofilter (servletrequestrequest, servletresponse  Response, filterchain chain)  throws IOException,          ServletException         {                     Response.setcontenttype ("Text/html;charset=utf-8");                    super.dofilter (Request,response, chain);          }            @Override &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp;   protected grouptemplategetgrouptemplate ()  {                     Returnservletgrouptemplate.instance (). Getgrouptemplate ();          }           }


3 , compiling templates HTML (not required for HTML or a different suffix)

Create a new pseudo-model file ( For example, to test the template webroot/views/common/header.html).

4 , creating a pseudo-data model

The newly established webroot/values/common/header.html.var,values is the root of the default pseudo-model for the listener.

var userlist = {id:2, name: "User One"};


Some common variables can be placed in the In the Webroot/values/common.var . The listener executes the Common.var first and then executes the Common/header.html.var.


The above record description inevitably appear wrong wording, hope you Sheng, thank you.


This article from "Good memory than bad writing" blog, please be sure to keep this source http://gytian.blog.51cto.com/1065457/1615842

One of the tools of web development technology--BEETL use notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.