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

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

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

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

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

@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 = "公告标题", required = true) @RequestParam String title,@ApiParam(name = "content", value = "公告内容", required = true)  String content,

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

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

对于Restful风格

@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 = "恢复被删除的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))}

【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别相关推荐

  1. Spring Boot注解

    文章目录 简介 @SpringBootApplication @EnableAutoConfiguration 条件自动配置 @ConditionalOnClass 和 @ConditionalOnM ...

  2. 超级详细的Spring Boot 注解总结

    日常编程中我相信大家肯定都用过spring,也用过spring的注解,哪怕面试的时候也经常会被问到一些spring和spring boot注解的作用和含义等,那么这篇就带大家来看看超级详细的Sprin ...

  3. Spring Boot 注解原理

    Spring Boot 注解原理 首先,先看SpringBoot的主配置类: @SpringBootApplication public class StartEurekaApplication {p ...

  4. Spring Boot注解的运行原理

    Spring Boot 是一个基于 Spring Framework 的开源框架,通过简化配置和开发过程,使 Spring 应用程序的开发变得更加快速和便捷.在 Spring Boot 中,注解是非常 ...

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

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 来源:www.cnblogs.com/tanwei81/p/681 ...

  6. 【建议收藏】Spring Boot注解全梳理!

    一.注解(annotations)列表 @SpringBootApplication:包含了**@ComponentScan**.「@Configuration」 和 「@EnableAutoConf ...

  7. Spring Boot 注解大全,一键收藏!回城路上复习!

    点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 来源 | www.cnblogs.com/tanwei8 ...

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

    点击上方 好好学java ,选择 星标 公众号 重磅资讯.干货,第一时间送达今日推荐:2020年7月程序员工资统计,平均14357元,又跌了,扎心个人原创100W+访问量博客:点击前往,查看更多 Sp ...

  9. Spring Boot注解详解

    文章目录 使用注解的优势 注解详解(配备了完善的释义) 注解列表如下 JPA注解 springMVC相关注解 全局异常处理 项目中具体配置解析和使用环境 使用注解的优势 采用纯java代码,不在需要配 ...

最新文章

  1. Python游戏开发,Pygame模块,Python从零开始带大家实现魔塔小游戏
  2. pythonselenium实战 excel读取和写入_Python3.6+selenium2.53.6自动化测试_读取excel文件的方法...
  3. spring中的RowMapper
  4. easyExcel 读取日期为数字的解决方案
  5. 2008 R2 Server core 下的常用命令
  6. android连接耳机时音量控制,android – 扬声器音量(闹钟)在插入耳机时会降低
  7. Android日志[进阶篇]一-使用 Logcat 写入和查看日志
  8. 计算机控制 重修,计算机控制技术重修复习提纲.doc
  9. BZOJ.4727.[POI2017]Turysta(哈密顿路径/回路 竞赛图)
  10. MySQL 5.7原生JSON格式支持
  11. 薄板样条插值(Thin plate splines)的实现与使用
  12. matlab多目标遗传算法工具箱,运用MATLAB遗传算法工具箱求解非线性多目标优化问题,...
  13. dnf单机版 不显示服务器,dnf单机云服务器
  14. 高登学苑-解密携程4.9分的秘诀学习笔记
  15. App开发之前的工作准备和开发中的一些流程
  16. uilable 上面加子视图图
  17. 【Python+Appium】开展自动化测试(七)截图方法
  18. [转载] 我叫李小帅
  19. 二向箔-百日打卡writeup26-30
  20. 太香了!Python 50 个正则表达式写法

热门文章

  1. jq之slideDown() stop()
  2. java中asl_带你认识绕不开的ASLR
  3. db2中null和空值的区别_MySQL数据库的表中 NULL 和 空值 到底有什么区别呢?
  4. python selenium 下载文件_Python Selenium —— 文件上传、下载,其实很简单
  5. 在C语言中023是八进制数,C语言总结
  6. 银联分账与银联代付_第三方分账系统到底有哪些作用?
  7. Linux输入密码接口,Linux下搭建接口自动化测试平台
  8. 【JAVA基础篇】集合框架
  9. git revert和reset区别
  10. (二)双线性插值python实现