Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Thymeleaf asterisk expressions

Shulou Source: shulou.com Published: 2022-06-01 23:55:22 10月01日 Update

Most people do not understand the knowledge points of this article "Thymeleaf asterisk expression", so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Thymeleaf asterisk expression how to use" article.

When working with templates, you typically use the variable expression ${.} to display variables, and you can also use the selected object expression * {.}, also known as an asterisk expression.

If the object is selected first in the template, you need to use an asterisk expression. Thymeleaf's built-in object # object effect is equivalent to an asterisk expression.

Development environment: IntelliJ IDEA 2019.2.2

Spring Boot version: 2.1.8

Create a new Spring Boot project named demo.

1 、 pom.xml

Join Thymeleaf dependency

Org.springframework.boot spring-boot-starter-thymeleaf

2 、 src/main/java/com/example/demo/User.java

Package com.example.demo;public class User {Integer id; String name; public User (Integer id, String name) {this.id = id; this.name = name;} public Integer getId () {return id;} public void setId (Integer id) {this.id = id;} public String getName () {return name } public void setName (String name) {this.name = name;}}

3 、 src/main/java/com/example/demo/TestController.java

Package com.example.demo;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import java.util.ArrayList;import java.util.List;@Controllerpublic class TestController {@ RequestMapping ("/") public String test (Model model) {List users = queryUsers (); model.addAttribute ("user", users.get (0)); model.addAttribute ("users", users); return "test" } private List queryUsers () {List users = new ArrayList (); users.add (new User (1, "Zhang San"); users.add (new User (2, "Li Si"); users.add (new User (3, Wang Wu)); return users;}}

4 、 src/main/resources/templates/test.html

Title table {border-collapse:collapse;} td {border: 1px solid # C1DAD7 } use variable expressions use asterisk expressions: use asterisk expressions: use # object objects to use asterisk expressions in the body of a loop

Browser access: http://localhost:8080

The following screenshot is shown:

The above is about the content of this article on "how to use Thymeleaf asterisk expressions". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Expressions asterisks content objects variables articles templates knowledge articles values names most that is loop bodies situations screenshots effects more steps browsers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn Huawei Microsoft Docker