SpringBoot(四):SpringMVC注解+restful

1.SpringMVC注解

  • @RequestMapping(常用):支持 Get 请求,也支持 Post 请求
  • @GetMapping:RequestMapping 和 Get 请求方法的组合,只支持 Get 请求。Get 请求主要用于查询操作。
  • @PostMapping:RequestMapping 和 Post 请求方法的组合,只支持 Post 请求,Post 请求主要用户新增数据
  • @PutMapping:RequestMapping 和 Put 请求方法的组合,只支持 Put 请求,Put 通常用于修改数据
  • @DeleteMapping:RequestMapping 和 Delete 请求方法的组合,只支持 Delete 请求·通常用于删除数据
  • @RestController =@Controller + @ResponseBody

2. restful

2.1啥是restful?

一种互联网软件架构设计的风格,但它并不是标准,它只是提出了一组客户端和服务器交互时的架构理念和设计原则,基于这种理念和原则设计的接口可以更简洁,更有层次, REST这个词,是 Roy Thomas Fielding 在他 2000 年的博士论文中提出的。任何的技术都可以实现这种理念,如果一个架构符合 REST 原则,就称它为 RESTFul 架构。

2.2SpringBoot开发restful

以下为例:

@RequestMapping(value = "/student/detail/{id}/{age}")
    public Object student1(@PathVariable("id")Integer id,
                            @PathVariable("age")Integer age){
       ......
    }

猜你喜欢

转载自blog.csdn.net/qq_41984117/article/details/111143313