1、系统要求
- Java 8 & 兼容java14 .
- Maven 3.3+
- idea 2019.1.2
2、需求
要求:浏览发送/hello请求,响应 Hello,Spring Boot 2
创建maven工程
pom依赖如下
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
创建启动类
/**
* 主程序类
* @SpringBootApplication:这是一个SpringBoot应用
*/
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
编写控制器
@RestController
public class HelloController {
@RequestMapping("/hello")
public String handle01(){
return "Hello, Spring Boot 2!";
}
}
启动
查看控制台日志
这里端口是8081、访问http://localhost:8081/hello
成功输出。