搭建一个简单的springboot架构
时间: 2024-05-08 15:15:23 浏览: 7
1. 创建一个Maven项目
2. 在pom.xml中添加spring-boot-starter-parent依赖
3. 在pom.xml中添加spring-boot-starter-web依赖
4. 创建一个Spring Boot启动类,使用@SpringBootApplication注解
5. 创建一个Controller类,使用@RestController注解
6. 在Controller类中编写接口方法,使用@RequestMapping注解
7. 运行Spring Boot应用,访问接口地址测试是否正常
示例代码:
1. 创建Maven项目
2. pom.xml
```
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
```
3. Spring Boot启动类
```
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```
4. Controller类
```
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "Hello, Spring Boot!";
}
}
```
5. 运行应用
在IDEA中运行Application类的main方法,或者使用命令行运行:
```
mvn spring-boot:run
```
6. 测试接口
访问http://localhost:8080/hello,应该能看到返回的字符串"Hello, Spring Boot!"。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)