1. Spring Getting Started-Spring Fifth Edition

This chapter is a quick overview of spring and spring boot, and initializing a spring project.

1. What is spring

The core of spring is a container, usually referring to the spring application context, creating and managing application beans. The assembly of individual beans is another way of relying on dependency injection (DI) to control inversion IOC.
Insert picture description here

2. Initialize a spring application

There are 6 ways to use Spring Initializr to initialize a spring application:

  • Via the website http://start.spring.io;
  • Use the curl command;
  • 使用Spring Boot command-line interface;
  • Use Spring Tool Suite, referred to as spring STS;
  • Use IntelliJ IDEA;
  • Use NetBeans;

Here is generated using Eclipse's spring tool suite . Please see here for how to install spring tool suite in Eclipse .

2.1 Use spring STS to initialize spring project

From File->
Insert picture description here
New- > Spring Starter Project, choose spring web, Thymeleaf, Spring Boot DevToo.
Insert picture description here

2.2 Engineering structure

Insert picture description here

3. Write a spring application

3.1 Processing web requests

package tacos;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @Description: It is for test.
 * @create: 2019-12-29 22:19
 */
@Controller
public class HomeController {
	@GetMapping("/")
	public String home() {
		return "home";
	}
}

3.2 Definition page

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">
	<head>
	<meta charset="UTF-8">
	<title>Taco Cloud</title>
	</head>

	<body>
		<h1>Welcome to ...</h1>
		<img th:src="@{/images/TacoCloud.png}" />
	</body>
</html>

The project structure is as follows
Insert picture description here

3.3 Start engineering test

Insert picture description here

3.4 Understanding Spring Boot DevTools

As its name suggests, DevTools provides the following development tools:

  • When the code changes, it restarts automatically;
  • When web resources change, such as JavaScript, etc., the browser automatically refreshes the page;
  • Template caching is automatically disabled.
Published 97 original articles · praised 3 · 10,000+ views

Guess you like

Origin blog.csdn.net/qq_39530821/article/details/103690977