
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

@Controller
public class MyController {
@RequestMapping("/hello")
public String handleRequest() {
return "Hello, World!";
}
}

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

这个博客展示了如何使用Spring Boot创建一个简单的RESTful服务。通过添加`spring-boot-starter-web`依赖,我们可以创建一个控制器类`MyController`,里面定义了一个处理/hello请求的方法,返回'Hello, World!'。最后,`@SpringBootApplication`注解启动了Spring Boot应用。

被折叠的 条评论
为什么被折叠?



