实现步骤:
1.创建Maven项目
2.导入SpringBoot起步依赖
3.定义Controller
4.编写引导类
5.启动测试
创建一个模块,选用Maven模块,GroupId内填入包名,ArtfactId内填入springboot-helloword
在pom.xml中写入
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
创建HelloController类,放在com.it.controller包下
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "hello Spring Boot!";
}
}
创建HelloApplication类,放在com.it包下
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
在网页写
localhost:8080/hello