1.在idea中新建一个空项目,添加一个Spring Initializr模块
2.在pom.xml中添加以下配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<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>
3.在自动生成的java package下新建一个control包,写一个controller类
@RestController
public class HelloController {
@RequestMapping(value="/hello",method = RequestMethod.GET)
public String getHello(){
return"Hello Spring Boot";
}
}
(类上面RestController注解不要遗漏)
4.运行DemoApplication类(模块创建自动生成)
控制台出现以下样示则表示代码通过也可通过postman进行测试