What are the basic operations and concepts of getting started with SpringBoot?
1. What is Spring Boot
Why should you learn Spring Boot?
Spring was born to simplify the development of Java programs, and Spring Boot was born to simplify the development of Spring programs.
Spring Boot is the scaffolding of the Spring framework. It was born for the rapid development of the Spring framework.
2. Spring Boot Advantages
Quickly integrates frameworks. Spring Boot provides the function of starting to add dependencies, which is used to integrate various frameworks in seconds.
Built-in running container, no need to configure Web containers such as Tomcat, run and deploy programs directly.
Rapidly deploy projects to get your projects up and running without the need for external containers.
You can completely abandon the cumbersome XML and use annotations and configuration for development.
Supports more monitoring indicators to better understand the running status of the project.
3.Spring Boot project creation
Create using Idea [provided by ide developer]
Web version creation method [Officially provided by Spring]
The Spring Boot project has two main directories:
src/main/java is the Java source code.
src/main/resources is static resources or configuration files:
/static: static resource folder;
/templates: template resource folder.
4.1 Project operation
Click the main method of the startup class to run the Spring Boot project. The successful startup is as shown in the following figure:
4.2 Output Hello world
We learn JavaEE to implement Web projects or interfaces. Before, Spring was actually an ordinary Java project, and there was no way to interact directly with the browser, so next we have to use Spring Boot is used to interact with browsers and users.
Create the HelloController file under the created project package path. The implementation code is as follows:
package com.example.demo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("/hi")//路由映射 public class HelloController { @RequestMapping("/index")//路由映射 @ResponseBody//返回一个非静态页面的数据 public String sayHi(){ return "你好,Spring Boot"; } }
Restart the project and visit http://localhost:8080/hi/index. The final effect is as follows:
5. Note - Package path error
We try to move HelloController to other packages, such as the following methods:
Run our project and found that the program reported an error, as shown in the following figure:
This means that the Spring Boot project did not inject objects into the container middle.
5.1 Correct path
When we put the container class and startup class to be injected into the same directory, as shown in the following figure:
At this time, the Spring Boot project can normally inject beans into the container.
5.2 Summary
Convention is greater than configuration
The above situation reflects another feature of the Spring Boot project: convention is greater than configuration.
We can also see this feature in Spring projects. For example, in Spring, the scanning path of beans must be configured, but in Spring Boot, this is not required. The Spring configuration is as follows:
Note:
The classes annotated in the 5 major categories must be placed in the same directory as the startup class or in a subdirectory of the startup class, otherwise they will not be recognized
The above is the detailed content of What are the basic operations and concepts of getting started with SpringBoot?. For more information, please follow other related articles on the PHP Chinese website!

How to correctly configure apple-app-site-association file in Baota nginx? Recently, the company's iOS department sent an apple-app-site-association file and...

How to understand the classification and implementation methods of two consistency consensus algorithms? At the protocol level, there has been no new members in the selection of consistency algorithms for many years. ...

mybatis-plus...

The difference between ISTRUE and =True query conditions in MySQL In MySQL database, when processing Boolean values (Booleans), ISTRUE and =TRUE...

How to avoid data overwriting and style loss of merged cells when using EasyExcel for template filling? Using EasyExcel for Excel...

How to switch from Java programmers to audio and video development? Learning Paths and Resources Recommendations If you are a Java programmer and are participating in a video project, �...

How to efficiently count the number of node services in MYSQL tree structure in Java? When using MYSQL database, how to count the number of nodes in the tree structure...

How do newcomers choose Java project management tools for backends? Newbie who are just starting to learn back-end development often feel confused about choosing project management tools. Special...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment