Springboot project creation and testing


foreword

I learned the project creation of springboot in class, so I want to share my learning results with you. If you have any questions, you can leave a message and correct them.


1. Local configuration

  1. Windows 10 system
  2. Understand IDEA 2018
  3. JDK 1.8
  4. apache-maven-2.7.9

2. Operation steps

1. Click

Open IDEA, click Configure in the lower right corner , and then click the Settings option .
(This picture is the IDEA2017 I used, which was actually built in the 2018 version)
The picture was built by me with IDEA2017

2. Modify Settings

In the search box in the upper left corner, enter maven, and it will be displayed as shown in the figure.

figure 1

  1. Maven home directory is best to choose the version you downloaded, mine is maven version 3.8.5, click on the three dots at the back, and select the location of your maven file
  2. User settings file is generally gray, check the Override behind, you can change the path. The path is the settings.xml file in the conf folder under the maven file.
  3. Local repository is generally gray, check the Override behind, you can change the path. I create a new .m2 folder in my springBootsoft folder, and then create a repository folder.

Note : The maven warehouse is divided into remote warehouse and local warehouse. When you configure a dependent project in pom, maven will first search for the project from the local warehouse. If it is not found, it will pass the configured address or default address (if no remote warehouse address is configured ) Download the project through the remote warehouse and save it in the .m2 folder.
If you want to modify the location of the local warehouse, you can configure it in the settings.xml file in the conf folder under the maven folder, and add the following content:
address

For example, if I want to change the warehouse to the mavenRepository folder on the E drive, I will add the following content:
E:/mavenRepository
so that the project package downloaded by maven will be downloaded to this folder.

insert image description here

Then click Runner in Maven on the left, and select your own JDK for JRE on the right. Mine is the current version of JDK1.8.

insert image description here
After everything is done, click the Apply button in the lower right corner, and click OK.

3. Create a project

1. Click Create New Project
(this picture is IDEA2017 I used, which was actually built in version 2018)
The picture was built by me with IDEA2017
2. Click Spring Initializr on the left, and then click Next in the lower right corner. (Network operation is required)
insert image description here
3. You can modify the names of Group and Artifact by yourself, and select Maven as the Type . Since my JDK version is 1.8, I changed the Java Version to 8. You can decide according to your own situation. Finally click Next in the lower right corner.

Reference : groupId: the unique identifier of the enterprise or team that created the project, which defines which group/team the project belongs to. groupId is generally divided into multiple segments, the first segment is the domain, and the second segment is the company name.

artifactId : It is the unique identifier of the project, which actually corresponds to the name of the project, which is the name of the root directory of the project.

name: declares a more user-friendly project name, which is not required. It is recommended to declare a name for each pom to facilitate information exchange.

version : specifies the current version of the project, and SNAPSHOT means a snapshot, indicating that the project is still under development and is an unstable version.

groupid and artifactId are collectively referred to as "coordinates" to ensure the uniqueness of the project. If you want to get your project to the maven local warehouse, you must search according to these two ids if you want to find your project.

insert image description here

4. First click the Spring Boot in the middle to select the version number. Here I choose version 2.7.9, then click the Web option on the left, click the Spring Web option on the right, and finally click Next on the lower right foot.
insert image description here
5. Finally click Finish.

insert image description here
Waiting for download.

3. Test

1. Click the application.properties file in src\main\resources on the left , and the port number is 8080.

sever.port=8080

insert image description here

2. Create a new controller folder under src\main\java\com\rj02\springbootdemorj02 on the left, and then create a HelloController.java file inside.
insert image description here

3. Write code

package com.rj02.springbootdemorj02.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hello")
public class HelloController {
    
    
    @RequestMapping("/index")
    public String index(){
    
    
        return "Hello World";
    }
}

insert image description here

4. Click the Springbootdemorj02Application file on the left, and then click the green triangle in the file to start the file.

insert image description here

5. Open your own browser and enter http://localhost:8080/hello/index URL.

insert image description here

Summarize

The above is what I learned today. This article only briefly introduces the project creation and testing of springboot. There are still many places that have not been explored. If you have any questions above, you can correct them. Thank you.

Guess you like

Origin blog.csdn.net/qq_52992084/article/details/129467917