要在服务上使用Spring Boot,可以按照以下步骤进行操作:
org.springframework.boot
spring-boot-starter-web
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyController {
@GetMapping("/hello")
public String hello() {
return "Hello, Spring Boot!";
}
}
当你访问http://localhost:8080/hello
时,将返回"Hello, Spring Boot!"的响应。
这是一个基本的示例,你可以根据自己的需求进行扩展和定制。
上一篇:按请求URI过滤视图
下一篇:按奇偶排序数组的结果不稳定。