1.@ApiParam,就是用于swagger提供开发者文档,文档中生成的注释内容。

  1. @ApiOperation( value = "编辑公告", notes = "编辑公告", httpMethod = "POST" )
  2. @RequestMapping( value = "/edit", method = RequestMethod.POST )
  3. public RequestResult edit(
  4. @ApiParam(name = "title", value = "公告标题", required = true) @RequestParam("title") String title,
  5. @ApiParam(name = "content", value = "公告内容", required = true) @RequestParam("content") String content){

2.@RequestParam,是获取前端传递给后端的参数,可以是get方式,也可以是post方式。

其中如果前端传递的参数和后端你接受的参数起的名字字段是一致的可以省略不写,所以@RequestParam("title") String title 也可以直接写@RequestParam String title。

如果不一致一定要完整写,不然获取不到,如下面的bis_key就必须写。

  1. @ApiOperation( value = "编辑公告", notes = "编辑公告", httpMethod = "POST" )
  2. @RequestMapping( value = "/edit", method = RequestMethod.POST )
  3. public RequestResult edit(
  4. @ApiParam(name = "bis_key", value = "bis_key", required = true)@RequestParam("bis_key") String bisKey,
  5. @ApiParam(name = "title", value = "公告标题", required = true) @RequestParam String title,
  6. @ApiParam(name = "content", value = "公告内容", required = true) String content,

3.@PathVariable,是获取get方式,url后面参数,进行参数绑定

  1. @ApiOperation(value = "删除公告", notes = "删除公告", httpMethod = "POST")
  2. @RequestMapping(value = "/delete/{bisKey}", method = RequestMethod.POST)
  3. public RequestResult remove(@ApiParam(name = "bisKey", value = "需要删除的公告ids", required = true) @PathVariable String bisKey) {

对于Restful风格

  1. @PatchMapping("api/v1/staff/{id}")
  2. @ApiOperation(value = "修改staff")
  3. @ApiImplicitParams(
  4. ApiImplicitParam(name = TokenService.TOKEN_HEADER, defaultValue = TokenService.TOKEN_STARTS, value = "access_token", dataType = "string", paramType = "header")
  5. )
  6. @Transactional
  7. fun patch(
  8. @RequestHeader(name = TokenService.TOKEN_HEADER, required = true)
  9. token: String,
  10. @PathVariable("id") id: Long,
  11. @RequestBody request: CreateStaffRequest
  12. ): GenericResponse<StaffData> {
  13. val user = this.user(token).user
  14. var staff = this.staffService.findStaff(id)
  15. staff = this.staffService.updateStaff(
  16. staff = staff,
  17. realname = request.realname,
  18. mobile = request.mobile,
  19. idCard = request.idCard,
  20. gender = request.gender,
  21. password = request.password,
  22. subCompanyId = request.subCompanyId,
  23. departmentId = request.departmentId,
  24. roleIdSet = if (request.roleIdSet.count() <= 0) throw BadRequestException("roleIdSet大小不能为0") else request.roleIdSet,
  25. enabled = request.enabled,
  26. updater = user
  27. )
  28. return GenericResponse(
  29. items = StaffData(staff)
  30. )
  31. }
  32.  
  33. @DeleteMapping("api/v1/staff/{id}")
  34. @ApiOperation(value = "删除staff")
  35. @ApiImplicitParams(
  36. ApiImplicitParam(name = TokenService.TOKEN_HEADER, defaultValue = TokenService.TOKEN_STARTS, value = "access_token", dataType = "string", paramType = "header")
  37. )
  38. @Transactional
  39. fun delete(
  40. @RequestHeader(name = TokenService.TOKEN_HEADER, required = true)
  41. token: String,
  42. @PathVariable("id") id: Long
  43. ): GenericResponse<StaffData> {
  44. val user = this.user(token).user
  45. var staff = this.staffService.findStaff(id)
  46. staff = this.staffService.deleteStaff(
  47. staff = staff,
  48. operator = user
  49. )
  50.  
  51. return GenericResponse(
  52. items = StaffData(staff)
  53. )
  54. }
  55.  
  56. @PutMapping("api/v1/staff/{id}")
  57. @ApiOperation(value = "恢复被删除的staff操作")
  58. @ApiImplicitParams(
  59. ApiImplicitParam(name = TokenService.TOKEN_HEADER, defaultValue = TokenService.TOKEN_STARTS, value = "access_token", dataType = "string", paramType = "header")
  60. )
  61. @Transactional
  62. fun restore(
  63. @RequestHeader(name = TokenService.TOKEN_HEADER, required = true)
  64. token: String,
  65. @PathVariable("id") id: Long
  66. ): GenericResponse<StaffData> {
  67. val user = this.user(token).user
  68. var staff = this.staffService.findStaff(id)
  69. staff = this.staffService.restoreStaff(staff, user)
  70. return GenericResponse(
  71. items = StaffData(staff)
  72. )
  73. }

【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别的更多相关文章

  1. @Requestbody@ApiParam @PathVariable @RequestParam三者区别

    一.问题描述 由于项目是前后端分离,因此后台使用的是spring boot,做成微服务,只暴露接口.接口设计风格为restful的风格,在get请求下,后台接收参数的注解为RequestBody时会报 ...

  2. @ApiParam @PathVariable @RequestParam三者区别

    转载:https://www.cnblogs.com/xu-lei/p/7803062.html @ApiParam @PathVariable @RequestParam三者区别 1.@ApiPar ...

  3. Spring Boot注解大全,一键收藏了!

    本文首发于微信公众号[猿灯塔],转载引用请说明出处 今天是猿灯塔“365天原创计划”第5天. 今天呢!灯塔君跟大家讲: Spring Boot注解大全 一.注解(annotations)列表 @Spr ...

  4. Spring boot注解(annotation)含义详解

    Spring boot注解(annotation)含义详解 @Service用于标注业务层组件@Controller用于标注控制层组件(如struts中的action)@Repository用于标注数 ...

  5. Spring boot 注解简单备忘

    Spring boot 注解简单备忘 1.定义注解 package com.space.aspect.anno;import java.lang.annotation.*; /** * 定义系统日志注 ...

  6. 73. Spring Boot注解(annotation)列表【从零开始学Spring Boot】

    [从零开始学习Spirng Boot-常见异常汇总] 针对于Spring Boot提供的注解,如果没有好好研究一下的话,那么想应用自如Spring Boot的话,还是有点困难的,所以我们这小节,说说S ...

  7. Spring Boot 注解之ObjectProvider源码追踪

    最近依旧在学习阅读Spring Boot的源代码,在此过程中涉及到很多在日常项目中比较少见的功能特性,对此深入研究一下,也挺有意思,这也是阅读源码的魅力之一.这里写成文章,分享给大家. 自动配置中的O ...

  8. Spring Boot 注解的使用

    Spring Boot 优于Spring mvc ,SSM,SSH 的一个亮点就是他使用了好多的注解. 1. @Autowired 这个注解的作用是将其他的类,接口引入,类似于之前的类的初始化等,用这 ...

  9. Spring Boot 注解详解

    一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...

随机推荐

  1. 初涉最小表示法&&bzoj1398: Vijos1382寻找主人 Necklace

    把最小表示法的坑填了 Description 给定两个项链的表示,判断他们是否可能是一条项链. Input 输入文件只有两行,每行一个由0至9组成的字符串,描述一个项链的表示(保证项链的长度是相等的) ...

  2. Linux用户身份(命令详解与补正)

    基于Red Hat Enterprise Linux 7.5 Linux中的root就是存在于所有类UNIX系统中的超级用户,持有最高管理权限,能添加/删除用户.开关机.关闭或开启硬件或者系统服务等, ...

  3. find 命令search使用

    GNU在目录树中查找的时候,是根据所给的名字从根节点开始从左到右匹配.根据优先级规则,直到在某一个节点找到结果了才会移动到下一个文件名字. 1.找空目录 find  ./path -depth -ty ...

  4. Django REST framework 五种增删改查方法

    Django-DRF-视图的演变   版本一(基于类视图APIView类) views.py: APIView是继承的Django View视图的. 1 from .serializers impor ...

  5. day12-图

  6. (转)ios 代码规范

    转自http://blog.csdn.net/pjk1129/article/details/45146955 引子 在看下面之前,大家自我检测一下自己写的代码是否规范,代码风格是否过于迥异阅读困难? ...

  7. loj2003 「SDOI2017」新生舞会

    分数规划+KM 算法 这个KM不好,看算法竞赛进阶指南的 #include <iostream> #include <cstring> #include <cstdio& ...

  8. python基础-文件和目录

    字符串小练习 >>> s="1a2a3a4a5a" >>> s1=s.split('a') >>> >>> ...

  9. unittest编写Web测试用例

    案例:百度搜索关键词:“unittest” test_baidu.py: from selenium import webdriver from time import sleep import un ...

  10. Redis学习笔记01---配置文件

    1.配置文件用法 启动redis的时候指定配置⽂件路径: ./redis-server /path/to/redis.conf 不指定配置⽂件的时候使⽤内置配置⽂件启动,此⽅法仅适⽤于开发和测试. 2 ...