1、打开java左上角的 File
New
Project
2、选择 Maven
选择 JDK,其它的不用改变
Next
3、选择保存路径,给项目命一个名字Name,然后点击Finish创建完成
4、创建成功
5、在 pom.xml中添加
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
6、单机右侧Maven中的刷新
7、 在Main的Java下新建一个类,名字为com.sdect.Main,点击回车,创建成功
8、为Main类中添加主函数
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class,args);
}
}
9、在com.sdcet下新建一个包名字为controller,回车确定
10、在controller包下新建一个名为HelloController的类,回车确定
11、为HelloController添加以下语句
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@ResponseBody
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "Hello SpringBoot!!!";
}
}