[Getting started with Spring Boot] How to quickly create a Spring Boot project

Quickly create Spring Boot projects

The emergence of SpringBoot simplifies Spring application development

With the development of technology, it is much more convenient to create a SpringBoot project. Let me mainly introduce two methods of creating a SpringBoot project.

1. Quick creation method of official website:

(1) First click on the official website Spring Initializr

We can see the following page, select the configuration and dependencies according to the requirements (follow the picture below)

Group and Artifact name themselves, and finally click GENERATE to generate the Jar package.

(2) Unzip the Jar package into a folder, and open the project with IDEA

 

 2. IDEA creates a Spring Boot project (HelloWorld)

(1)

 

(2) Finally, a simple SpringBoot project was created (forget the screenshot, steal the picture of method 1, they are the same in structure)

(3) The main program is written like this, so that the main program can be started

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class WorldApplication {

	public static void main(String[] args) {
		SpringApplication.run(WorldApplication.class, args);
	}

}

tips:

(1) psvm + Enter key --> public static void main(String[ ] args)

(2) SpringApplication.run(): Spring application startup method

(3) Pass in the main program class HelloWorldMainApplication.class

(4) Pass in the variable function args[ ] of the main method

(5) (exclude = DataSourceAutoConfiguration.class)//Disable the automatic configuration of the database

(4) Choose to automatically import dependencies

Select Enable Auto-Import (enable IDEA function) to enable automatic import dependencies

In this way, every time a dependency is written in pom.xml, IDEA will automatically import related dependencies

(5) Write (business logic) related Controller and Server

package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//指定控制器,用于处理请求
@Controller
public class HelloController {

    @ResponseBody//把return的内容写给浏览器

    @RequestMapping("/hello")//接受来自浏览器的hello请求

    public String hello(){
        return "hello";//返回一个字符串“hello”在浏览器上
    }
}

Tips: The main program.java is at the upper level of Controller.java, they are of different levels

(6) Run the main program test

(7) Simplify deployment work 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_51583068/article/details/124658599