Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of Common Grammar in Thymeleaf

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "Thymeleaf common grammar summary". In daily operation, I believe many people have doubts about Thymeleaf common grammar summary. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Thymeleaf common grammar summary". Next, please follow the editor to study!

1. Template inheritance: write the common part of the page to one page, and other pages get the common part by inheriting the page.

Create a public page base-layout.html with the following content:

Added jquery library and website icons.

Xmlns:layout: importing layout tags

Layout:fragment: declare layout identity

Inherit hello.html from base-layout.html:

Layout:decorator: indicates the use of a template decoration, that is, the parent template

Layout:fragment: represents the block corresponding to the inherited parent template, which can be understood as the parent class method in Java.

This page does not import the Jquery library, but we can already use Jquery to show that the template inherited successfully.

two。 Common syntax:

First, write some data to the page in the CommonResponse::sayHello method

The tags in Thymeleaf correspond to: tags in th:HTML, so you don't need to remember them separately.

Th:value: the value tag in html.

Th:each: iterative variable, you can define two iterative variables, 1: iterative variable (u), 2: iterative state quantity (uStat)

Th:if: conditional judgment, it is recommended to use eq,lt,gt,ne instead of =,! =, some symbols such as & need to use escaped symbols (&)

Th:attr: used to set the value of an attribute. The above code corresponds to: id= [u.id], which is usually used for non-html tags such as data-toggle. Please note that uppercase characters will be automatically converted to lowercase. For example, data-Toggle will be converted to data-toggle.

# dates,#lists is a Thymeleaf global variable, there are many more, please check the documentation when you need it.

Use th:inline: to indicate the content type, which is generally: text,javascript.

Th:inline= "text": use this tag to use the Thymeleaf syntax directly. If you need to write js on the page, use it. If the code block contains operators or other special symbols, use the CDATA enclosing method body:

Or

Sample page:

At this point, the study of "Thymeleaf Common Grammar Summary" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report