使用IDEA快速创建Springboot项目

快速创建SpringBoot项目

简介

SpringBoot是Spring家族特别重要的一员,能够大大简化spring的配置。

SpringBoot官网

快速创建SpringBoot项目

进入快速创建SpringBoot项目的官网

配置好对应的选项

image-20221219152851678

点击右侧的ADD DEPENDENCIES选项,添加spring web依赖包

image-20221219153025959

点击GENERATE按钮,会让你下载一个zip包,这就是我们的springboot项目

使用IntelliJ IDEA创建SpringBoot项目

当然,IDEA也为我们提供了快速创建Springboot项目的方法,用的就是上面Spring官网的接口

image-20221219160208489

选择web,点击创建

创建UserController类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.example.controller;

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

/**
* @author makun
* @project spring-boot
* @description 用户控制类
* @date 2022/12/19 17:34:48
* version 1.0
*/
@RestController
@RequestMapping("/user")
public class UserController {
@RequestMapping("/{id}")
public String getUserById(@PathVariable int id) {
System.out.println("id ---> " + id);
return "hello Spring boot";
}
}

点击启动,控制台出现以下内容,表示启动成功

image-20221219173925854

访问http://127.0.0.1:8080/user/1,如果显示hello Spring boot,表示访问成功