GetMapping thiab PostMapping yog dab tsi?
GetMapping thiab PostMapping yog dab tsi?

Video: GetMapping thiab PostMapping yog dab tsi?

Video: GetMapping thiab PostMapping yog dab tsi?
Video: Spring & Spring Boot Annotations Series - #14 - @GetMapping Annotation 2024, Kaum ib hlis
Anonim

Cov lus piav qhia rau daim phiaj HTTP GET thov mus rau cov txheej txheem tshwj xeeb. Tshwj xeeb, @ GetMapping yog ib qho annotation uas ua raws li qhov shortcut rau @RequestMapping(txoj kev = RequestMethod. GET). Txij li thaum: 4.3 Sau: Sam Brannen Saib Ntxiv: PostMapping , PutMapping, DeleteMapping, PatchMapping, RequestMapping.

Cov lus nug tseem yog, qhov txawv ntawm GetMapping thiab PostMapping yog dab tsi?

Los ntawm lub rooj sib tham naming peb tuaj yeem pom tias txhua qhov kev piav qhia yog txhais tau los ua cov lus thov nkag los ntawm hom, piv txwv li @ GetMapping yog siv los lis hom GET ntawm thov txoj kev, @ PostMapping yog siv los lis POST hom ntawm thov txoj kev, thiab lwm yam.

Qhov thib ob, vim li cas peb siv @PostMapping? @ PostMapping los lis HTTP POST Thov Daim Ntawv Ceeb Toom tias txoj kev lav phib xaub rau kev tuav HTTP POST thov yuav tsum tau sau tseg nrog @ PostMapping lus piav qhia. Daim ntawv ceeb toom yuav ua li cas @RequestBody annotation yog siv txhawm rau khij cov qauv kev sib cav uas cov ntaub ntawv JSON yuav raug hloov los ntawm Spring Framework.

Ib yam li ntawd, nws tau nug, @PostMapping yog dab tsi?

Cov lus piav qhia rau daim phiaj HTTP POST thov mus rau cov txheej txheem tshwj xeeb. Tshwj xeeb, @ PostMapping yog ib qho annotation uas ua raws li qhov shortcut rau @RequestMapping(txoj kev = RequestMethod.

@GetMapping yog dab tsi thaum caij nplooj ntoos hlav?

1.1. @Controller Annotation Caij nplooj ntoos hlav MVC muab cov lus piav qhia raws li txoj hauv kev uas koj tsis tas yuav txuas ntxiv ib chav hauv paus los nthuav qhia daim ntawv thov, thov kev nkag tsis tau, zam kev tuav, thiab ntau dua. @Controller yog cov lus piav qhia zoo sib xws uas kos ib chav kawm raws li tus neeg thov kev thov.

Pom zoo: