springboot helloworld示例
时间: 2023-05-01 22:01:11 浏览: 156
Spring Boot Hello World 示例:
1. 创建一个 Spring Boot 项目
2. 在项目中新建一个控制器类,如下代码所示:
```java
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String sayHello() {
return "Hello Spring Boot";
}
3. 在项目中新建一个启动类,如下代码所示:
```java
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);
}
}
```
4. 启动项目并在浏览器中访问 localhost:8080/hello, 应该会看到输出 "Hello Spring Boot".
阅读全文