Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop Web applications

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to develop Web applications. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Static resource access

When we develop Web applications, we need to refer to a large number of static resources such as js, css, pictures and so on.

Default configuration

Spring Boot provides static resource directory location by default, which needs to be placed under classpath. The directory name must comply with the following rules:

/ static

/ public

/ resources

/ META-INF/resources

For example: we can create a static in the src/main/resources/ directory and place an image file in that location. After starting the program, try to access http://localhost:8080/D.jpg. If the picture can be displayed, the configuration is successful.

Render the Web page

In the previous example, we all processed the request through @ RestController, so the return is a json object. So how do you do that when you need to render html pages?

Template engine

Spring Boot can still be perfectly competent in the implementation of dynamic HTML, and provides default configuration support for a variety of template engines, so we can quickly start to develop dynamic websites under the recommended template engine.

Spring Boot provides the following template engines with default configuration:

Thymeleaf

FreeMarker

Velocity

Groovy

Mustache

Spring Boot recommends using these template engines to avoid using JSP. If you must use JSP, you will not be able to achieve many features of Spring Boot. For more information, please see below: support 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 also modify this path, and how to modify it can be queried and modified in the configuration properties of subsequent template engines.

Thymeleaf

Thymeleaf is a XML/XHTML/HTML5 template engine that can be used for application development in both Web and non-Web environments. It is an open source Java library licensed by Apache License 2.0, created by Daniel Fern á ndez, and author of the Java encryption library Jasypt.

Thymeleaf provides an optional module for integrating Spring MVC. In application development, you can use Thymeleaf to completely replace JSP or other template engines, such as Velocity, FreeMarker, etc. The main goal of Thymeleaf is to provide a well-formatted way to create templates that can be displayed correctly by browsers, so it can also be used as static modeling. You can use it to create validated XML and HTML templates. As opposed to writing logic or code, developers only need to add tag attributes to the template. These tag attributes then perform predetermined logic on the DOM (document object Model).

Sample template:

Name Price Oranges 0.99

You can see that Thymeleaf is mainly added to the html tag in the form of attributes, and when the browser parses html, it will ignore the attributes that are not found, so the template of Thymeleaf can be opened and displayed directly through the browser, which is very conducive to the separation of front and rear.

To use Thymeleaf in Spring Boot, you only need to introduce the following dependencies and write a template file under the default template path src/main/resources/templates.

Org.springframework.boot spring-boot-starter-thymeleaf, thank you for your reading! This is the end of the article on "how to develop Web applications". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report