1.创建一个工程
(1)New Project 选择Spring Initalizr
(2)填写信息
(3)选择需要的jar
(4)pom.xml引入web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
(5)测试
右键自动生成的类,出现图中启动图形。输入http://localhost:8080
2.新建web项目包
(1)创建controller包
(2)创建HelloController类
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController//注解 修饰该Controller所有的方法返回JSON格式
public class HelloController {
@RequestMapping("/hello")
public String index() {
return "Hello World";
}
}
(3)运行测试