[Java2023] T4-WEB入门-创建第一个SprintBoot程序

100 阅读1分钟
  • 目标是创建第一个spring boot程序, 并且在浏览器能够输入'hello world'

  • 1.创建项目

image.png

  • 2.勾选Spring Web (注意, 选择2.7.x版本就行, 不用选最新的)

image.png

  • 3.创建完之后, 删除多余的文件夹(.idea 也删掉)

image.png

  • 4.创建Controller

image.png

  • 5.编写代码
package com.itheima.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

// 添加Rest注解, 表示它是一个用于请求处理的类
@RestController
public class HelloController {
    // 用注解定义请求路由
    @RequestMapping("/hello")
    public String hello() {
        System.out.println("hello spring");
        return "hello spring";
    }
}
  • 6.启动SpringBoot

image.png