SpringBoot - [02] 第一个SpringBoot程序
- jdk
- maven3.6.3
- springboot最新版
- idea
如果使用官网 Spring Initializr ,则需要jdk17、21、22,并且是Springboot3.x
可以在idea创建一个简单的maven项目,然后引入相关依赖即可进行Springboot的相关开发。
一、引入依赖
<!-- 父项目 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
</parent>
<!-- maven依赖 -->
<dependencies>
<!-- WEB依赖: Tomcat,dispatcherServlet.xml -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- 属性配置 -->
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
二、编写代码
包名:src/main/java
类名:MyApplication.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author harley
* @date 2024/04/10 14:58
*/
@RestController
@EnableAutoConfiguration
public class MyApplication {
@RequestMapping("/")
String home(){
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class,args);
}
}
运行代码,在页面访问localhost:8080 即可
— 要养成终生学习的习惯 —
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南