"Java template language" Tinytemplate combat < one >:serlvet integration

Source: Internet
Author: User

Writer:bysocket (mud and brick pulp carpenter)

First, what is Tinytemplate

What is a template language?

The template language is created to separate the user interface from the business data (content) and can generate documents in a specific format.

What is Tinytemplate? ( Open Source project address entry )

Tiny template engine is a Java technology-based template engine, it has a small volume, high performance and expansion of the characteristics of easy. Suitable for all scenarios that generate text type content through text templates, such as XML, source files, HTML, and so on, it can be said that it appears to replace the velocity template engine, so that on the instruction set as far as possible with the velocity of the same time, It also expands the instructions and functions that velocity does not solve the problem well, and in many ways it is as consistent with Java as possible, so it is easy to learn and use.

1. Small volume performance in a total of less than 5,000 lines of code, remove the parser nearly 1000 lines, the core engine only more than 4,000 lines of code.

2. High performance in the current domestic several high-performance template engine, such as: Jetbrick, Webit and other engine performance compared to nearly about, but compared to velocity, freemarker and so on have made great progress, efficiency is roughly four times times the velocity.

3. Extensibility in all environments of the tiny framework engine can be self-expandable and well integrated with the original system.

4. Easy to learn is demonstrated in the tiny framework concept clear, module division of Science, with very high high cohesion and low coupling.

5. Flexible use of the table now, can be multiple cases, a single case, and can be well integrated with spring and so on.

6. Friendly error message.


Brief Feature Introduction:

1. Similar to Velocity instructions, the same or similar instructions up to about 90%

2. Support for variable parameter method invocation

3. Support for class member method overloading

4. Support function Extension

5. Using the weak type method, the template layer code to write less constraints, how the model layer changes, template layer code adjustment is very easy

6. Support macro Definition #macro

7. Support Layout #layout

Second, integrate with Servlet, run Hello,world

1. Create a new quickstart.servlettemplate maven project

in Eclipse, New-maven project-"Maven-archetype-quickstart" ...

add a dependency to Tinytemplate on Pom.xml:

    <!--the template engine extends dependency on Servlets-    <dependency>  <groupId>org.tinygroup</groupId>  <artifactId>org.tinygroup.templateservletext</artifactId>  <version>2.0.26</version ></dependency>
With the above code, rewrite the Tinyservlet HandleRequest method, and then perform the logical processing inside, return the index.page. 4. Add Default.layout and Index.page default.layout:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" ><!--[if IE 7]> &L t;html class= "No-js ie IE7 lte7 lte8 lte9" lang= "en-US" > <! [endif]--><!--[If IE 8]>   Index.page: 
${name}, welcome to the world of tiny! Time: ${date}
5. Run the project, right-click the project run As-maven build-"Jetty:run". Access localhost:8080/project name/index Third, summary

1. Introduction and characteristics of Tinytemplate

2, Tinytemplate and servlet configuration (next talk with SPRINGMVC configuration)

3, Tinytemplate The simplest is also the most commonly used value syntax ${}

Welcome to click on my blog and github-blog to provide RSS Subscription Oh!

———-http://www.bysocket.com/————-https://github.com/JeffLi1993 ———-

Weibo: Bysocket watercress: Bysocket facebook:bysocket twitter:bysocket


Java template Language Tinytemplate combat < >:serlvet integration

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.