@GetMapping @PostMapping @PutMapping @DeleteMapping @PathVariable(占坑)

springboot 增删改查

@GetMapping @PostMapping  @PutMapping @DeleteMapping

@PathVariable

通过 @PathVariable 可以将URL中占位符参数{xxx}绑定到处理器类的方法形参中@PathVariable(“xxx“

@GetMapping("/{id}")
@ResponseBody
public User getUsersById(@PathVariable int id) {
return new User(id,"sunrui","123");
}

@ResponseBody

绕开视图解析器,返回json对象

@GetMapping
@ResponseBody
public List<User> getUsers(){
return userService.queryUserList();
}

@RequestBody

public String addUsers(@RequestBody User user){
return "success";
}

原文地址:https://www.cnblogs.com/Master-Sun/p/14345938.html