除过使用IDEA自带的一键式生成Sping Boot,第二个就是直接使用maven工具来创建并管理项目,对于一个Spring Boot项目,需要以下几个步骤:
1.创建maven项目
File -> new -> Project -> Maven -> Next -> 给自己的项目命名 一般的命名格式为GroupId = xx.xx
,Artifactid =xx
-> Next 创建完成;
2.在pom文件中导入两个Spring Boot的依赖包
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
<dependecies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3.编写Controller类及ResponseBody响应体
package com.google.sboot.model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class User {
@ResponseBody
@RequestMapping("/hello")
public String helloWorld(){
return "Hello World";
}
}
4.编写SpringBootApplication
package com.google.sboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SbootApplication {
public static void main(String[] args) {
SpringApplication.run(SbootApplication.class, args);
}
}