Springboot Primer-Rendering pages using the Thymeleaf template engine

Source: Internet
Author: User

In the Web development, we are inevitably in the front page between the jump, the middle of the data query and so on. We used springboot before including me in fact, most of them are using JSP page, can say that the use of is already very familiar. However, after we use the Springboot development framework, we will find a fatal problem, that is, springboot JSP support can be said to be miserable, the official recommended that we use the Thymeleaf template engine. In fact, I don't know what the template engine principle is, we have a chance to get to know it later, we just have to learn how to use it, for now. Of course, there are many template engine, such as Freemarker and so on, but I have always felt thymeleaf relative to the freemarker to use or a lot of. Here we will only talk about thymeleaf this template engine!

The use is very simple, first we need to import the dependency in the Pom.xml file:

   

Next we can go to the application.properties file for the relevant configuration:

    

Here we need to explain:

1> This configuration is not required because Springboot has its own default configuration, and our configuration overrides the associated default configuration

2> we are on the page back, the page is stored by default in the templates file under the resource file.

3> Use thymeleaf default page is HTML page, so this is very convenient.

4> We do not configure the time is best to tell the template cache to close, has made the corresponding comments, because the purpose is to make changes in the page, we can quickly see the visual effect.

Then we just need to build the relevant page, and then in the Controller control layer in the corresponding jump to write:

   

  

So we use the Springboot framework to make use of Thymeleaf for page rendering return is also very convenient, there are many small partners have doubts, if I create a file in the Templates file storage page, this time we want to return to what should be done, In fact, we just add a layer of path, in general, we do not say that the use of the control layer in the return path is added, only in the configuration file can be combined:

  

  

  

Springboot Primer-Rendering pages using the Thymeleaf template engine

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.