第一个SpringBoot程序
Spring的配置繁琐,所以出现了SpringBoot,其目的是简化Spring的配置及开发。
创建SpringBoot项目
选择Spring Initializr
这里jdk我选择8
添加依赖
添加maven依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
编写HelloController
新建controller包,HelloController.java
package com.example.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @title: HelloController
* @Author 张宜强
* @Date: 2021/2/24 11:12
* @Effect:
*/
@RestController
public class HelloController {
@RequestMapping("/hello")
public String Hello() {
return "HelloSpringBoot!";
}
}
运行项目
运行代码,输入网址http://localhost:8080/hello
一个SpringBoot就完成了,不需要配置任何文件。