一个功能
浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串.
1.创建一个maven工程;(jar)
2.导入依赖Spring Boot相关的依赖
1 | 参考:<a target= "_blank" >https: //projects.spring.io/spring-boot/#quick-start</a> |
1 2 3 4 5 6 7 8 9 10 11 | <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version> 2.0 . 2 .RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> |
3.编写一个主程序;启动Spring Boot应用
4.编写相关Controller、Service
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | package hello; import org.springframework.boot.*; import org.springframework.boot.autoconfigure.*; import org.springframework.stereotype.*; import org.springframework.web.bind.annotation.*; @Controller @EnableAutoConfiguration public class SampleController { @RequestMapping ( "/" ) @ResponseBody String home() { return "Hello World!" ; } public static void main(String[] args) throws Exception { SpringApplication.run(SampleController. class , args); } } |
5.运行主程序测试
6.简化部署
pox.xml配置
1 2 3 4 5 6 7 8 | <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> |
可以将应用打包生成一个可执行的jar包
用代码行来衡量开发进度,无异于用重量来衡量制造飞机的进度。
【推荐】AI 的力量,开发者的翅膀:欢迎使用 AI 原生开发工具 TRAE
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 本可避免的P1事故:Nginx变更导致网关请求均响应400
· 还在手写JSON调教大模型?.NET 9有新玩法
· 复杂业务系统线上问题排查过程
· 通过抓包,深入揭秘MCP协议底层通信
· 记一次.NET MAUI项目中绑定Android库实现硬件控制的开发经历
· 推荐 6 款基于 .NET 开源的串口调试工具,调试效率提升利器!
· 《HelloGitHub》第 112 期
· 千万级的大表如何新增字段?
· AI 的力量,开发者的翅膀:欢迎使用字节旗下的 AI 原生开发工具 TRAE
· 大模型的JSON之殇:从脆弱的API调用到稳健的未来