日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别

發(fā)布時(shí)間:2025/3/8 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.@ApiParam,就是用于swagger提供開(kāi)發(fā)者文檔,文檔中生成的注釋內(nèi)容。

@ApiOperation( value = "編輯公告", notes = "編輯公告", httpMethod = "POST" )@RequestMapping( value = "/edit", method = RequestMethod.POST )public RequestResult edit(@ApiParam(name = "title", value = "公告標(biāo)題", required = true) @RequestParam("title") String title,@ApiParam(name = "content", value = "公告內(nèi)容", required = true) @RequestParam("content") String content){

?

2.@RequestParam,是獲取前端傳遞給后端的參數(shù),可以是get方式,也可以是post方式。

其中如果前端傳遞的參數(shù)和后端你接受的參數(shù)起的名字字段是一致的可以省略不寫(xiě),所以@RequestParam("title") String title 也可以直接寫(xiě)@RequestParam String title。

如果不一致一定要完整寫(xiě),不然獲取不到,如下面的bis_key就必須寫(xiě)。

@ApiOperation( value = "編輯公告", notes = "編輯公告", httpMethod = "POST" )@RequestMapping( value = "/edit", method = RequestMethod.POST )public RequestResult edit(@ApiParam(name = "bis_key", value = "bis_key", required = true)@RequestParam("bis_key") String bisKey,@ApiParam(name = "title", value = "公告標(biāo)題", required = true) @RequestParam String title,@ApiParam(name = "content", value = "公告內(nèi)容", required = true) String content,

?

3.@PathVariable,是獲取get方式,url后面參數(shù),進(jìn)行參數(shù)綁定

@ApiOperation(value = "刪除公告", notes = "刪除公告", httpMethod = "POST")@RequestMapping(value = "/delete/{bisKey}", method = RequestMethod.POST)public RequestResult remove(@ApiParam(name = "bisKey", value = "需要?jiǎng)h除的公告ids", required = true) @PathVariable String bisKey) {

對(duì)于Restful風(fēng)格

@PatchMapping("api/v1/staff/{id}")@ApiOperation(value = "修改staff")@ApiImplicitParams(ApiImplicitParam(name = TokenService.TOKEN_HEADER, defaultValue = TokenService.TOKEN_STARTS, value = "access_token", dataType = "string", paramType = "header"))@Transactionalfun patch(@RequestHeader(name = TokenService.TOKEN_HEADER, required = true)token: String,@PathVariable("id") id: Long,@RequestBody request: CreateStaffRequest): GenericResponse<StaffData> {val user = this.user(token).uservar staff = this.staffService.findStaff(id)staff = this.staffService.updateStaff(staff = staff,realname = request.realname,mobile = request.mobile,idCard = request.idCard,gender = request.gender,password = request.password,subCompanyId = request.subCompanyId,departmentId = request.departmentId,roleIdSet = if (request.roleIdSet.count() <= 0) throw BadRequestException("roleIdSet大小不能為0") else request.roleIdSet,enabled = request.enabled,updater = user)return GenericResponse(items = StaffData(staff))}@DeleteMapping("api/v1/staff/{id}")@ApiOperation(value = "刪除staff")@ApiImplicitParams(ApiImplicitParam(name = TokenService.TOKEN_HEADER, defaultValue = TokenService.TOKEN_STARTS, value = "access_token", dataType = "string", paramType = "header"))@Transactionalfun delete(@RequestHeader(name = TokenService.TOKEN_HEADER, required = true)token: String,@PathVariable("id") id: Long): GenericResponse<StaffData> {val user = this.user(token).uservar staff = this.staffService.findStaff(id)staff = this.staffService.deleteStaff(staff = staff,operator = user)return GenericResponse(items = StaffData(staff))}@PutMapping("api/v1/staff/{id}")@ApiOperation(value = "恢復(fù)被刪除的staff操作")@ApiImplicitParams(ApiImplicitParam(name = TokenService.TOKEN_HEADER, defaultValue = TokenService.TOKEN_STARTS, value = "access_token", dataType = "string", paramType = "header"))@Transactionalfun restore(@RequestHeader(name = TokenService.TOKEN_HEADER, required = true)token: String,@PathVariable("id") id: Long): GenericResponse<StaffData> {val user = this.user(token).uservar staff = this.staffService.findStaff(id)staff = this.staffService.restoreStaff(staff, user)return GenericResponse(items = StaffData(staff))}

?

總結(jié)

以上是生活随笔為你收集整理的【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。