赞
踩
目录
本文使用相应的版本号:springboot2.7.0、openjdk18.0.1、maven3
Spring Boot 可以快速地创建基于生产级的spring项目。大多数Spring Boot应用只要引入其快速启动的依赖即可使用
springboot官方参考文档地址:Spring Boot Reference Documentation
1.创建一个maven项目,在pom.xml文件中继承spring-boot父工程
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.7.0</version>
- </parent>
2.添加web依赖
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
3.更新maven项目后,新建一个java类,在类上添加注解:
@RestController
@EnableAutoConfiguration
创建一个方法,并使用@RequestMapping注解设置映射路径
- 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;
-
- /**
- * springboot入门
- */
-
- @RestController
- @EnableAutoConfiguration
- public class HelloWorldApplication {
- public static void main(String[] args) {
- SpringApplication.run(HelloWorldApplication.class, args);
- }
-
- @RequestMapping("/")
- String home() {
- return "Hello World!";
- }
- }
4.运行HelloWorldApplication,运行成功后控制台打印启动信息如下:
5.运行成功后,在浏览器中输入localhost:8080,显示信息如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。