学习日志Springboot学习日志
liefSpringBoot入门 - SpringBoot hello LEE
通过 IDE 集成工具创建
IntelliJ IDEA:
File → New → Project
选择 “Spring Boot”
配置项目信息和依赖项
点击create,完成创建
修改Sb1Application代码即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| package com.example.sb1;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
// Spring Boot应用程序的主类,包含启动方法和REST控制器 @SpringBootApplication @RestController
public class Sb1Application {
// 程序入口点,启动Spring Boot应用 public static void main(String[] args) { SpringApplication.run(Sb1Application.class, args);
} // 处理GET请求的/hello端点,返回问候信息 @GetMapping("/hello") public ResponseEntity<String> hello() { // 返回包含"hello LEE"消息和HTTP 200状态的响应 return new ResponseEntity<>("hello LEE", HttpStatus.OK); } }
|