We have experienced a simple RESTful API development service;
To load static resource access
When we develop Web applications, we need to cite a large number of JS, CSS, pictures and other static resources.
Default configuration
Spring boot defaults to provide static resource directory locations that need to be placed under Classpath, and directory names should conform to the following rules:/static/public/resources/meta-inf/resources
For example: We can create static in the src/main/resources/directory and place a picture file at that location. After you start the program, try to access http://localhost:8080/GG.jpg. If the picture can be displayed, the configuration is successful.
Rendering Web pages
In the previous example, we all handled the request through @restcontroller, so the returned content was a JSON object. So if you need to render HTML pages, how do you implement them?
Template engine
Spring boot is still perfect for dynamic HTML implementations and provides the default configuration support for a variety of template engines, so we can quickly start developing dynamic Web sites under the recommended template engine.
Spring Boot provides the default configuration of the template engine mainly as follows: Thymeleaf freemarker Velocity Groovy Mustache
Spring Boot recommends using these template engines to avoid using JSPs, and it will not be possible to implement the many features of Spring boot, as shown in the following article: Support for JSP configuration
When you use any of the above template engines, their default template configuration path is: Src/main/resources/templates. Of course, you can modify this path, specifically how to modify, in the subsequent template engine configuration properties to query and modify.
Thymeleaf
Thymeleaf is a XML/XHTML/HTML5 template engine that can be used for application development in Web and non-web environments. It is an open source Java library, based on the Apache License 2.0 license, created by Daniel Fernández, author of the Java Cryptographic Library Jasypt.
Thymeleaf provides an optional module for integrating Spring MVC, where you can use Thymeleaf to completely replace a JSP or other template engine, such as velocity, freemarker, and so on. The primary goal of Thymeleaf is to provide a well-formed template creation method that can be properly displayed by the browser, and therefore can also be used as a static model. You can use it to create validated XML and HTML templates. Instead of writing logic or code, developers simply add tag attributes to the template. Next, these tag properties perform predefined logic on the DOM (Document Object model).
Sample Template:
<th th:text= |
#{msgs.headers . Name} ' |