入门 —— 创建一个 SpringBoot 项目
1. 使用 idea 创建一个 maven 工程
项目之前已经创建,所以报红(创建路径下新项目即可)
2. 项目结构
<parent>
<groupId>org.springframework.boot</groupId
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3. 创建启动类
package com.zfy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author 江湖@小小白
* @create 2021/10/9 15:04
*/
@SpringBootApplication
public class MySpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class);
}
}
4. 创建与前端交互的controller
package com.zfy.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author 江湖@小小白
* @create 2021/10/9 15:09
*/
@Controller
public class TestController {
@RequestMapping("/questTest")
@ResponseBody
public String questTest(){
return "SpringBoot 访问成功";
}
}