新建Springboot项目
(1)file->new->project
(2)点击next(第一个)
创建springboot项目
(3)点击next(第二个)
选择web-》spring web starter
(4)点击next(第三个)
不用做修改,直接finish
新建springboot项目已经完成。
springboot默认生成三个文件
默认生成的三个文件
pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.4.RELEASE
com.laowang
sptest
0.0.1-SNAPSHOT
sptest
Demo project for Spring Boot
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2.2.2 application.properties
该文件默认为空,springboot的默认启动端口号:8080,可以在改文件修改。
2.2.3 启动类文件(SptestApplication.java)
package com.laowang.sptest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SptestApplication {
public static void main(String[] args) {
SpringApplication.run(SptestApplication.class, args);
}
}
2.3 验证springboot
在com.laowang.sptest报下新建ctroller包,并新建类:HelloController
package com.laowang.sptest.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
@Controller
public class HelloController {
@RequestMapping("/")
@ResponseBody
public String getHello() {
return "hello";
}
}