• @PathVariable :主要用于动态绑定url

      • 案例

        1. //@PathVariable("id") String videoId "id"必须与url中的{id}保持一致
        2. @PostMapping("/{id}/like")
        3. public ResponseEntity<Long> likeComment(@PathVariable("id") String videoId) {
        4. try {
        5. Long likeCount = this.videoService.likeComment(videoId);
        6. if (likeCount != null) {
        7. return ResponseEntity.ok(likeCount);
        8. }
        9. } catch (Exception e) {
        10. e.printStackTrace();
        11. }
        12. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        13. }
    • @RequestParam :将请求参数绑定到你控制器的方法参数上(是springmvc中接收普通参数的注解)

      • 案例
        1. @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    • @RequestBody :可以绑定自定义的对象类型的参数

      • 案例
        1. @RequestBody Map<String, String> param;
        2. param.get("nickname");