Springboot环境搭建_第一个例子
首先创建一个maven项目
maven项目创建完成之后,找到pom.xml配置节点。需要springboot-starter-web ,springboot-starter-test,springboot-starter-parent,springboot-starter-plugin。
pom.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>cn.happy</groupId> <artifactId>11SpringBoot</artifactId> <version>0.0.1-SNAPSHOT</version> <name>11SpringBoot</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.7</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
这样环境搭建完成。
做第一个例子,首先创建一个controller:
controller代码:
package cn.happy; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping("/hello") public String ob(){ System.out.println("我们进入了App"); return "success"; } }
之后在App类中加上一个注解:SpringbootApplication
在App类的mian方法中调用 : SpringApplication.run(App.class,args);
package cn.happy; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Hello world! * */ @SpringBootApplication public class App { public static void main( String[] args ) { SpringApplication.run(App.class,args); } }
然后启动mian方法:
打开百度输入controller方法的路径:
第一个例子完成。
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
【推荐】AI 的力量,开发者的翅膀:欢迎使用 AI 原生开发工具 TRAE
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
· InnoDB为什么不用跳表,Redis为什么不用B+树?
· 记一次 C# 平台调用中因非托管 union 类型导致的内存访问越界
· [EF Core]聊聊“复合”属性
· 那些被推迟的 C# 14 特性及其背后的故事
· 我最喜欢的 C# 14 新特性
· C#/.NET/.NET Core技术前沿周刊 | 第 49 期(2025年8.1-8.10)
· 微软开源的 MCP 教程「GitHub 热点速览」
· 记一次 .NET 某汽车控制焊接软件 卡死分析
· InnoDB为什么不用跳表,Redis为什么不用B+树?
· 博客园出海记-开篇:扬帆启航