日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

springboot 中 Getmapping獲取參數的方式

作者:暗里著迷° 更新時間: 2024-03-22 編程語言

Springboot中Getmapping使用PathVariable、HttpServletRequest、RequestParam獲取參數

@PathVaribale 獲取url中的數據

@RequestParam 獲取請求參數的值


    @GetMapping(value = "/getVideoPlayInfos")
    public List<GetPlayInfoResponse.PlayInfo> getVideoPlayInfos(@RequestParam(value = "videoId") String videoId) throws Exception {
        return getVideoPlayInfoResponseList(videoId);
    }

@RequestParam注解使用后

@PathVariable使用方法

    @GetMapping(value = "/getVideoPlayInfos/{videoId}")
    public List<GetPlayInfoResponse.PlayInfo> getVideoPlayInfos(@PathVariable(value = "videoId") String videoId) throws Exception {
        return getVideoPlayInfoResponseList(videoId);
    }

?使用后,直接在url后面拼接參數

@RequestMapping是一個無方法的注解。@GetMapping和@PostMapping是組合注解,分別是@RequestMapping(method = RequestMethod.GET)和@RequestMapping(method = RequestMethod.POST)的縮寫。
GET、POST是方法的映射,表示為
@RequestMapping(method = RequestMethod.${方法})

在一開始的映射是使用@RequestMapping(method = RequestMethod.${方法})來表示。后來Spring4.3中引進了@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping注解來幫助簡化常用的HTTP方法的映射。

什么時候用GET,什么時候用POST?

GET方法:客戶端與服務端之間是讀取操作(如搜索、讀、查詢操作)。
POST方法:
1.交互是一個命令或訂單(order),比提問包含更多信息
2.交互改變了服務器端的資源并被用戶察覺,例如訂閱某項服務
3.用戶需要對交互產生的結果負責

根據HTTP協議規定,GET方法可以攜帶交互需要的所有數據,因此你會看到搜索百度或谷歌的時候,點擊搜索形成的URL包含了你剛才的搜索關鍵字,沒有安全需求的請求把信息放URL里沒關系,但是你訪問銀行網站的時候,不希望把賬戶、密碼這些放在URL里被人攔截是吧,所以HTTP設計了POST請求,他可以把請求信息放在HTTP請求里,具體格式這里不細說了,這樣你就不能簡單的從URL里找到賬戶、密碼了。

原文鏈接:https://blog.csdn.net/FengLiu0077/article/details/124129047

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新