1.REST简介
行为动作
通常模块名使用复数,也就是加s
2.RESTful入门
@Controller
public class UserController {
@RequestMapping(value = "/users", method = RequestMethod.POST)
public String save() {
System.out.println("user save");
return "save";
}
/**
* @PathVariable:表示路径中对应的占位符
* @param id
* @return
*/
@RequestMapping(value = "/users/{id}", method = RequestMethod.DELETE)
public String delete(@PathVariable Integer id){
System.out.println("delete ..." + id);
return "delete";
}
/**
* @RequestBody:接收前端传递给后端的json字符串
* @param user
* @return
*/
@RequestMapping(value = "/users",method = RequestMethod.PUT)
public String update(@RequestBody User user){
System.out.println(user);
return "put";
}
}
1.步骤:
2.RequestMapping:映射
3.@PathVariable:路径占位符
4.@RequesBody:接收前端传递给后端的json字符串
5.@RequestBody,@RequestVariable,@RequestParam区别
3.REST快速开发
@RequestMapping("/books")
@RestController//RequestBody+Controller
public class BookController {
@PostMapping("/save")
public String save() {
System.out.println("user save");
return "save";
}
@DeleteMapping("/delete")
public String delete(@PathVariable Integer id){
System.out.println("delete ..." + id);
return "delete";
}
@PutMapping("/update")
public String update(@RequestBody User user){
System.out.println(user);
return "put";
}
}