
资料内容:
af?1.1 What is Thymeleaf?What is Thymeleaf?What is Thymeleaf?
1.1 What is Thymeleaf?
Thymeleaf is a modern server-side Java template engine for both web and standalone environments, capable of processing HTML, XML, JavaScript, CSS and
even plain text.
The main goal of Thymeleaf is to provide an elegant and highly-maintainable way of creating templates. To achieve this, it builds on the concept of Natural
Templates to inject its logic into template files in a way that doesn’t affect the template from being used as a design prototype. This improves
communication of design and bridges the gap between design and development teams.
Thymeleaf has also been designed from the beginning with Web Standards in mind – especially HTML5 – allowing you to create fully validating templates if
that is a need for you.
1.2 What kind of templates can Thymeleaf process?
Out-of-the-box, Thymeleaf allows you to process six kinds of templates, each of which is called a Template Mode:
HTML
XML
TEXT
JAVASCRIPT
CSS
RAW
There are two markup template modes ( HTML and XML ), three textual template modes ( TEXT , JAVASCRIPT and CSS ) and a no-op template mode ( RAW ).
The HTML template mode will allow any kind of HTML input, including HTML5, HTML 4 and XHTML. No validation or well-formedness check will be performed,
and template code/structure will be respected to the biggest possible extent in output.
The XML template mode will allow XML input. In this case, code is expected to be well-formed – no unclosed tags, no unquoted attributes, etc – and the
parser will throw exceptions if well-formedness violations are found. Note that no validation (against a DTD or XML Schema) will be performed.
The TEXT template mode will allow the use of a special syntax for templates of a non-markup nature. Examples of such templates might be text emails or
templated documentation. Note that HTML or XML templates can be also processed as TEXT , in which case they will not be parsed as markup, and every tag,
DOCTYPE, comment, etc, will be treated as mere text.
The JAVASCRIPT template mode will allow the processing of JavaScript files in a Thymeleaf application. This means being able to use model data inside
JavaScript files in the same way it can be done in HTML files, but with JavaScript-specific integrations such as specialized escaping or natural scripting. The
JAVASCRIPT template mode is considered a textual mode and therefore uses the same special syntax as the TEXT template mode.
The CSS template mode will allow the processing of CSS files involved in a Thymeleaf application. Similar to the JAVASCRIPT mode, the CSS template mode
is also a textual mode and uses the special processing syntax from the TEXT template mode.
The RAW template mode will simply not process templates at all. It is meant to be used for inserting untouched resources (files, URL responses, etc.) into the
templates being processed. For example, external, uncontrolled resources in HTML format could be included into application templates, safely knowing that
any Thymeleaf code that these resources might include will not be executed.