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

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

【IDEA】@RequestMapping與@GetMapping、@PostMapping的區(qū)別

作者:峰子的番茄肥牛 更新時間: 2024-03-22 編程語言

區(qū)別:

@GetMapping? ? ? ? ?用于HTTP的GET請求;

@PostMapping? ? ? ? 用于HTTP的POST請求;

@RequestMapping? ? ? ? 具有類屬性,可以進(jìn)行GET,POST,PUT或其他的注釋中具有的請求方法。

具體來說:

@GetMapping? ? ? ? ?組合注解,是@RequestMapping(method = RequestMethod.GET)的縮寫

@PostMapping????????組合注解,是@RequestMapping(method = RequestMethod.POST)的縮寫

@GetMapping ?@PostMapping?二者都是@RequestMapping的一個延伸,目的就是為了提高清晰度。

簡單示例:

@GetMapping演示:

controller層代碼

    @GetMapping("/get")
    @ResponseBody
    public String get(){
        return "get000";
    }

html使用get請求

?瀏覽器訪問

?使用@GetMapping,若修改為post提交,則會報錯405

---------------------------------------------------------------------------------------------------------------------------------

@RequestMapping??演示:

修改Controller層的@GetMapping@RequestMapping

//    @GetMapping("/get")    
    @RequestMapping("/get")
    @ResponseBody
    public String get(){
        return "get000";
    }

使用GET或POST都能夠正常跳轉(zhuǎn)。

?若定義中的method方法則需要與瀏覽器提交的方式一致

//get
@RequestMapping(value = "/get",method = RequestMethod.GET)
//post
@RequestMapping(value = "/get",method = RequestMethod.POST)

原文鏈接:https://blog.csdn.net/weixin_63453779/article/details/131605701

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