当前位置:网站首页>Introduce the difference between @getmapping and @postmapping in detail
Introduce the difference between @getmapping and @postmapping in detail
2022-07-26 19:16:00 【Work hard, work hard, gzc】
One 、 Preface
Want to know @GetMapping and @PostMapping The difference between , First of all, I need to understand @RequestMapping annotation .
understand @RequestMapping Please click me for comments
Two 、@GetMapping and @PostMapping The difference between
(1)@GetMapping yes @RequestMapping(method = RequestMethod.GET) Combined notes of abbreviations , Is used to HTTP Of get Request a method annotation that maps to a specific handler .
(2)@PostMapping yes @RequestMapping(method = RequestMethod.POST) Combined notes of abbreviations , Is used to HTTP Of post Request a method annotation that maps to a specific handler .
(3) Let's take a look at @GetMapping Source code 
The most important thing in the above figure is this line of code :
@RequestMapping( method = {RequestMethod.GET} )
This line of code explains @GetMapping Namely @RequestMapping Attached get Request method . in other words @GetMapping It's one that can only be used to deal with http Of get Requested comment , More specific , This is the only thing I can do , Unlike @RequestMapping Can handle a variety of http Request .
meanwhile , You can see @GetMapping This annotation yes spring4.3 Version to introduce , At the same time, the introduction of @PostMapping、@PutMapping、@DeleteMapping and @PatchMapping, altogether 5 A note .
(4) In general, our development may use @RequestMapping(method=RequestMethod.×××), because @RequestMapping You can directly replace the above two annotations , But the above two notes are not a substitute for @RequestMapping.
Similar combined annotations are also mentioned above :@PutMapping、@DeleteMapping、@PatchMapping Three annotations .
3、 ... and 、 summary
To sum up :@PostMapping、@GetMapping、@PutMapping、@DeleteMapping、@PatchMapping Both can be used. @RequestMapping Instead of , If you are afraid of making mistakes in mapping , It can be used in a unified way @RequestMapping(method=RequestMethod.×××), Of course, there are disadvantages in writing like this , General all use @RequestMapping, It is not convenient for others to read and understand the code ! It is still recommended to write separately , Develop good code habits !
边栏推荐
- Racher deploys kubernetes cluster
- LeetCode-138-复制带随机指针的链表
- 篇7:exited on DESKTOP-DFF5KIK with error code -1073741511.
- [postgraduate entrance examination vocabulary training camp] day 14 - Panini, predict, access, apologize, sense, transport, aggregation
- CTO will teach you: how to take over his project when a technician suddenly leaves
- Write a starter
- JS question brushing plan - array
- MySQL数据库命令大全
- Mongodb stats counts the space occupied by the collection
- Tensor Rt的int8量化原理
猜你喜欢

(ICLR-2022)TADA! Time adaptive convolution for video understanding

J1:Redis为什么这么快+基本结构

Verification palindrome string II of leetcode simple question

Introduction to Seata

2022年焊工(初级)操作证考试题库及模拟考试

VPC nat (Sant, nant) experiment

J2 Redis之 AOF&RDB

LeetCode-138-复制带随机指针的链表

The first letter of leetcode simple question appears twice

Covos: no need to decode! Semi supervised Vos acceleration using motion vectors and residuals of compressed video bitstreams (CVPR 2022)
随机推荐
Basic module and example pytorch learning
手写一个Starter
.net CLR GC dynamic loading transient heap threshold calculation and threshold excess calculation
JS question brushing plan - array
ReentrantLock学习之公平锁过程
[swoole series 3.1] have you been asked about processes, threads, and collaborations during the interview?
从6月25日考试之后,看新考纲如何复习PMP
一些时序建模策略(一)
Zbxtable 2.0 heavy release! 6 major optimization functions!
Reentrantlock learning --- basic method
ReentrantLock学习之---基本属性
rancher部署kubernetes集群
2022上海市安全员C证操作证考试题库模拟考试平台操作
VPC nat (Sant, nant) experiment
J1:Redis为什么这么快+基本结构
This article explains in detail the five benefits that MES system brings to enterprises, with application scenarios
Mathematical basis of deep learning
Write a starter
简述MES系统的11大核心功能模块
JS使用readline来实现终端输入数据