In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use the basic objects of Thymeleaf". In the daily operation, I believe that many people have doubts about how to use the basic objects of Thymeleaf. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to use the basic objects of Thymeleaf". Next, please follow the editor to study!
There are many built-in objects in Thymeleaf that can implement various functions in templates.
Here are a few basic objects.
Web objects are commonly used: request, session, servletContext.
Thymeleaf provides several built-in variables param, session, and application, which can access the request parameter, the session attribute, and the application attribute, respectively.
All properties of request can be accessed directly using ${attribute name}.
Note: built-in objects and built-in variables are two concepts. Built-in objects use the form of "${# object}", while built-in variables do not need "#".
Development environment: IntelliJ IDEA 2019.2.2
Spring Boot version: 2.1.8
Create a new Spring Boot project named demo.
1. Pom.xml joins Thymeleaf dependency:
Org.springframework.boot spring-boot-starter-thymeleaf
2 、 src/main/resources/templates/test1.html
The above can also be changed into the following ways:
3 、 src/main/java/com/example/demo/Test1Controller.java
Package com.example.demo;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import javax.servlet.http.HttpServletRequest;@Controllerpublic class Test1Controller {@ RequestMapping ("/ test1") public String test1 (@ RequestParam String name1, HttpServletRequest request) {request.setAttribute ("name2", "b"); request.getSession () .setAttribute ("name3", "c") Request.getServletContext () .setAttribute ("name4", "d"); return "test1";}
Browser access: http://localhost:8080/test1?name1=a
Page output:
Abcd can also be replaced with the following way: bcd at this point, the study on "how to use the basic objects of Thymeleaf" is over, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.