一. 创建maven工程,添加依赖
引入 spring-boot-starter以及 spring-boot-starter-web,版本选用的2.1.0.RELEASE
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.1.0.RELEASE</version> </dependency> </dependencies>
二. 创建启动类 DemoApplication
package com.xiaoxiaowang.springbootDemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author: xxw
* @create: 2022-10
*/
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
三. 启动springboot
四. 测试验证
五. 官网示例网址
Spring | Spring Quickstart GuideLevel up your Java code and explore what Spring can do for you.
https://spring.io/quickstart