Thymeleaf official document Chinese translation

1 introduction Thymeleaf

What 1.1 Thymeleaf that?

Thymeleaf is a modern server-side Java template engine web and independent environment, can handle HTML, XML, JavaScript, CSS, and even plain text.

Thymeleaf main goal is to provide an elegant and highly maintainable way to create a template. To achieve this, it is built on the concept of natural template, so as not to affect the template as a way to prototype logic used to inject the template file. This improves the exchange of design, and between design and development teams built a bridge.

Thymeleaf designed from the outset to consider the Web standards - especially HTML5-- allows you to create fully validated template, if you need it.

1.2 Thymeleaf what kind of template can handle?

Out of the box, Thymeleaf allows you to deal with six kinds of templates, each of which is known as template mode:

  • HTML
  • XML
  • TEXT
  • JAVASCRIPT
  • CSS
  • RAW

There are two modes marking template (HTML and XML), the three texts template mode (text, JAVASCRIPT and CSS) template and a non-operating mode (RAW).

HTML template mode will allow any type of HTML input, including HTML5, HTML 4 and XHTML. Will not perform any verification or check well format, and the code will respect the template / structure as in the output.

XML template mode will allow XML input. In this case, the code should be well-formed - no not closed tags, no unreferenced property, etc. - if you find a good format of the violation, the parser will throw an exception. Note will not perform any validation (against DTD or XML schema).

Text Template mode will allow the template to mark the nature of the non-use special syntax. Examples of such templates may be text or e-mail template document. Note, HTML, or XML templates can also be treated as text, in which case, they will not be parsed into tokens, and each token, DOCTYPE, comments and so on will be treated as plain text.

JAVASCRIPT JAVASCRIPT template mode will allow processing document Thymeleaf application. This means being able to use the same model as the data in the JavaScript file in an HTML file, but to use the JavaScript-specific integrated, such as special escape or natural script. JAVASCRIPT template mode is considered text mode, so the same special syntax and text template mode.

CSS template mode will allow CSS file Thymeleaf processing application involved. JAVASCRIPT model with similar, CSS template mode is a text-mode, and uses special treatment from the syntax template text mode.

The original template mode will not process template. It is used resource (file, URL, response, etc.) will not reach into the template being processed. For example, the external HTML format uncontrolled resources into the application template, but make sure that any code that these resources may contain Thymeleaf will not be executed.

1.3 dialect: standard dialect

Thymeleaf is a very extensible template engine (in fact it can be called a template engine framework), which allows you to define and customize the way your template will be treated to a fine level of detail.

Some logic to the workpiece mark (tag, some text, comments, if the template is not labeled, it is only a placeholder) object handler is called, these sets handlers - plus some additional work - usually dialect made of. Thymeleaf core library provides a dialect called standard dialect, which should be sufficient for most users.

Note that, dialect may not actually be the processor, and other types of work pieces entirely consisting of, but the processor is definitely the most common use cases.

This tutorial describes the standard dialect. In the following pages, each attribute syntax and features you will learn from this dialect is defined, even if not explicitly mentioned.

Of course, if you want to define your own processing logic at the same time take advantage of the advanced features of the library, users can create their own dialect (even extend the standard dialect). Thymeleaf may also be configured to use several dialects.

Official thymeleaf-spring3 and thymeleaf-spring4 integrated package defines a dialect called "SpringStandard dialect", most of the same standard dialect, but little to adapt better to use some features of the Spring framework (for example, through the use of Spring Expression Language Instead of exhibiting OGNL or image). So, if you are a Spring MVC user, you will not waste time, because almost all of what you learn here will be used in your Spring application.

Most processors are standard dialect attribute processor. This allows the browser to display the correct HTML template file before processing, because they will simply ignore additional attributes. For example, using a JSP tag library may contain a piece of code that can not be directly displayed in a browser, such as:

<form:inputText name="userName" value="${user.name}" />

Thymeleaf standard dialect will allow us to achieve the same functionality:

<input type="text" name="userName" value="James Carrot" th:value="${user.name}" />

This can not only be correctly displayed browser, but let us also (optionally) specify a value of property ( "James Carrot", in this case), the prototype will display static when opened in a browser, during the process template It will replace ${user.name}.

This helps designers and developers to deal with the same template file and convert static prototype to reduce the working template files needed work. To do so called natural template.

2 designing a great virtual grocery store

Source code samples, and subsequent chapters of this guide illustrated herein, may Good Thymes Virtual Grocery GitHub repository.

2.1 a grocery store site

In order to better explain the concept of using a template Thymeleaf process involved, this tutorial will use a demonstration application that you can download from the project's website.

This application is a virtual grocery store web site that will provide us with a number of scenarios to demonstrate the many features Thymeleaf.

First, our application needs a simple set of model entities: sales of products to customers by creating order. We will also review the management of these products:

Example application model

Guess you like

Origin www.cnblogs.com/wbyixx/p/11872929.html