一、@RequestParam
伪Post,类似get请求,参数会在请求路径中。请求形式:http://banks/getBanksListByCity?bankId=11&cityId=12@PostMapping(path = "/getBanksListByCity")@ResponseBodypublic ServiceResponseBean getBanksListByCity(@RequestParam("bankId") @NotBlank Long bankId,@RequestParam("cityId") @NotBlank Long cityId) { return banksService.getBanksListByBankId(bankId, cityId);}
二、@RequestBody
json结构参数转换成实体类。请求形式:http://user/addUser@PostMapping(path = "/addUser")@ResponseBodypublic ServiceResponseBean addUser(@RequestBody User user){ return userService.addUser(user));}
三、@PathVariable
请求参数是请求路径的一部分。请求形式:http://room/deleteRoom/111@DeleteMapping(path = "/deleteRoom/{id}")@ResponseBodypublic ServiceResponseBean deleteRoom(@PathVariable @NotBlank Long id) { return roomService.deleteRoomById(id);}