Now most of the development process is based on the idea integrated development environment. The author was very stubborn before and always used eclipse. Later, the company needed to switch to idea. I have to say that idea is indeed It’s easy to use, friends who have never used it can try it. Here, idea is used as the demonstration environment.
I usually start with an empty project, File-->New-->Project in idea, as shown on the left side of the picture below
## Select Maven and select JDK on the right. The "Create from archetype" below represents choosing a pom template. I am building an empty project here, so I don't choose it. Unless you are particularly sure, don't choose it. There will be unexpected surprises. Look at the next step, Write the project name. Here you can see that the project name and ArtifactId are the same, or they can be different. It is best to be the same. Oh, click "Finish" to complete the creation. The built project is as follows, You can see that the basic structure of a maven project is already there. Let's start the springboot journey. . 2. Start the springboot journeyNow development is all springboot web projects, which means that the service exists in the form of embedded tomcat, then we need to introduce dependencies,<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.3.3.RELEASE</version> </dependency>That is, add the above dependencies to the pom. You also need a startup class before,
package com.my.template; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; //springboot的启动注解 @SpringBootApplication public class BootServer { public static void main(String[] args) { //启动 SpringApplication.run(BootServer.class); } }Pay attention to the location of the startup class, BootServer.java is under the parent package com.my.template, If it is not there, some annotations may not be useful. I will talk about it later. Remember to remember the location of the startup class BootServer. We can just run the main method of BootServer.
##The above log appears, indicating that the service has been started and the port is 8080. Let’s access it,
This is because the root path 127.0.0.1:8080 has no content returned. Let’s write a test Controller to practice.
package com.my.template.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class TestServer { @ResponseBody @RequestMapping("test") public String test(){ return "hello springboot"; } }
Access the address 127.0.0.1:8080/test. The results are as follows,
# successfully returned "hello springboot", proving that our service is normal.
The above is the detailed content of How to quickly build a springboot project. For more information, please follow other related articles on the PHP Chinese website!