Spring Boot QuickStart (vi): THYMELEAF

Source: Internet
Author: User

Original address: HTTPS://LIERABBIT.CN/ARTICLES/8

Static resources

When we develop Web applications, we need to reference a large number of JS, CSS, pictures and other static resources.

The default location for Spring boot is resources/static

Template page

Various templates of the page, this time we choose Thymeleaf

The default location for Spring boot is resources/templates

Render page

In the previous example, we handled the request through @restcontroller, so the content returned was a JSON object. Use @controller when we need the page to find the template page

Add dependency

For projects that already exist, you can join in Bulid.gradle

Compile (' org.springframework.boot:spring-boot-starter-thymeleaf ') compile (' Org.springframework.boot: Spring-boot-starter-web ')

So far thymeleaf has introduced

Create a Controller

Create a new Thymeleafctrl class

Import Org.springframework.stereotype.controller;import Org.springframework.ui.model;import org.springframework.web.bind.annotation.RequestMapping; @Controller//This is a controller public class thymeleafctrl{    @ Requestmapping ("/") public    String Hello (model model)    {        model.addattribute ("Hello", "Hello Thymeleaf"); /Add a Hello variable with a value of "Hello Thymeleaf" to the view        return "Hello";//Find hello.html} in templates)    
Creating a template page

Create a hello.html page in Resources/templates

<! DOCTYPE html> 
  
Add a picture resource

Add Lierabbit.jpg in Resources/static

Run results

More thymeleaf syntax please visit the official website to view the document (http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html)

Source Address: Https://github.com/LieRabbit/SpringBoot-thymeleaf

Original address: HTTPS://LIERABBIT.CN/ARTICLES/8

Spring Boot QuickStart (vi): THYMELEAF

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.