Springboot Introduction to basic use of--thymeleaf engine templates

Source: Internet
Author: User

When we used the Springboot framework, we introduced the Thymelea engine template earlier because of Springboot's appalling support for JSP. So how can we load Dynamic Data on a static HTML page when we use the engine template to render the front page with the ability to return it? At this time we will introduce some basic methods of using Thymeleaf.

First, and our JSP page to import the C font is the same, we need to make certain configuration: as shown in the HTML tag to add two paragraphs

    

Text display: I saved a user object with a key value of User1 in the session, and I want to display its name directly on the page: use Th:text to

    

* Number arithmetic: We want to show all the properties of an object, this object has more than 10 properties, each time we have to use the object. Is the property displayed? At this point, the * operation arises:

    

Of course, our object creation is not necessarily only in Div, but also in block-level elements such as table.

If condition operation:

    

Selected Selection box default:

    

Each loop: Alias selection is used, which is similar to the item and VAR two properties of the foreach tag

    

Time Conversion: We use the data of date type directly when we use the background data time is very impersonal, so Thymeleaf provides the method of time conversion

URL Path Address:

    

Of course, we inevitably still need to be in the HTML page CSS and JS reference, then we should use when referring to:

1> configuration application.yml file: Because all of the static resources that we default in the Springboot framework are in the static folder

      

2> Edit JS File:

      

3>html page for reference:

Springboot Introduction to basic use of--thymeleaf engine templates

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.