1、选择File->New->Project,在对话框中选中Spring Initializr,给项目配置合适的SDK,点击Next.
2.根据需要选择Next直至Finish
3.运行Run->Edit Configurations。在弹出的对话框中新建一个Spring Boot配置,在右侧选择Main class,并填写其它相关的信息。点击OK保存配置文件。即可通过调试按钮启动一个Spring Boot调试了。
注意:第二步中,若没有选择Web->Web,则需要在pom中加入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
4.在启动类中加入@ComponentScan
5.创建DemoController
package com.example.controller;
import org.springframework.web.bind.annotation.*;
/**
* DemoController
*
* @author weixiang.wu
* @date 2018-07-02 17:10
**/
@RestController
@RequestMapping("/demo")
public class DemoController {
@RequestMapping(value = "/helloGet/{id}", method = RequestMethod.GET)
@ResponseBody
public String sayHello(@PathVariable("id") Long id) {
return "hello world,i'm get method,my lucky number is " + id;
}
@RequestMapping(value = "/helloPost", method = RequestMethod.POST)
@ResponseBody
public String sayHi(@RequestParam("id") Long id) {
return "hello world,i'm post method,my lucky number is " + id;
}
}
6.启动后访问demo接口
7.成功结束。