write a hello world spring boot in sts
时间: 2024-04-29 22:21:40 浏览: 8
Sure, here are the steps to create a "Hello World" Spring Boot application in STS:
1. Open Spring Tool Suite (STS) and navigate to File -> New -> Spring Starter Project.
2. In the "New Spring Starter Project" window, enter a name for your project and click "Next".
3. Select the "Web" dependency from the list of available dependencies and click "Finish".
4. STS will generate a new Spring Boot project with a basic structure.
5. Open the "src/main/java" folder and navigate to the package that was created for your project.
6. Right-click on the package and select "New" -> "Class".
7. Name the class "HelloController" and click "Finish".
8. Open the "HelloController" class and add the following code:
```java
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
}
```
9. Save the class and run the application by right-clicking on the project and selecting "Run As" -> "Spring Boot App".
10. Open a web browser and go to "http://localhost:8080/hello". You should see the message "Hello, World!" displayed in the browser.
That's it! You have created a "Hello World" Spring Boot application in STS.