入门实例 - HelloWorld
File > New > Spring Starter Project
项目创建完成:
这样就完成了项目的创建,下面我们创建一个 HelloController.java
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/hello")
public class HelloController {
static {
System.out.println("HelloController was on line!");
}
@RequestMapping("/SpringBoot")
public String hello() {
return "hello Spring Boot";
}
}
在浏览器输入 http://localhost:8080/bootdemo/hello/SpringBoot
输出 hello Spring Boot
实现成功!