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