新建项目
建好项目后把application.properties改成application.yml
之后开始编写UserController类
package com.javamk.sbdemo.web;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class UserController {
@GetMapping("/get/{id}")
public String get(@PathVariable Long id){
return "用户的ID是:" + id;
}
}
右键debug as –> spring boot App
出现Tomcat started on port(s): 8080 (http)时,输入网址
http://localhost:8080/user/get/4