一个功能
浏览器发送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包
用代码行来衡量开发进度,无异于用重量来衡量制造飞机的进度。
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步