1. 构建工程
a. 地址:http://start.spring.io/
b. 填写Group、Artifact
c. 生成工程、下载、解压
2. 项目结构
3. 添加controller内容
package com.jihite.helloworld.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping("/hello") public String index() { return "Hello World~"; } }
4. pom.xml
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
5. 运行main函数
请求:http://localhost:8080/hello
返回:Hello World~