【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别
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")
- )
- @Transactional
- fun patch(
- @RequestHeader(name = TokenService.TOKEN_HEADER, required = true)
- token: String,
- @PathVariable("id") id: Long,
- @RequestBody request: CreateStaffRequest
- ): GenericResponse<StaffData> {
- val user = this.user(token).user
- var 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")
- )
- @Transactional
- fun delete(
- @RequestHeader(name = TokenService.TOKEN_HEADER, required = true)
- token: String,
- @PathVariable("id") id: Long
- ): GenericResponse<StaffData> {
- val user = this.user(token).user
- var 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")
- )
- @Transactional
- fun restore(
- @RequestHeader(name = TokenService.TOKEN_HEADER, required = true)
- token: String,
- @PathVariable("id") id: Long
- ): GenericResponse<StaffData> {
- val user = this.user(token).user
- var staff = this.staffService.findStaff(id)
- staff = this.staffService.restoreStaff(staff, user)
- return GenericResponse(
- items = StaffData(staff)
- )
- }
【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别的更多相关文章
- @Requestbody@ApiParam @PathVariable @RequestParam三者区别
一.问题描述 由于项目是前后端分离,因此后台使用的是spring boot,做成微服务,只暴露接口.接口设计风格为restful的风格,在get请求下,后台接收参数的注解为RequestBody时会报 ...
- @ApiParam @PathVariable @RequestParam三者区别
转载:https://www.cnblogs.com/xu-lei/p/7803062.html @ApiParam @PathVariable @RequestParam三者区别 1.@ApiPar ...
- Spring Boot注解大全,一键收藏了!
本文首发于微信公众号[猿灯塔],转载引用请说明出处 今天是猿灯塔“365天原创计划”第5天. 今天呢!灯塔君跟大家讲: Spring Boot注解大全 一.注解(annotations)列表 @Spr ...
- Spring boot注解(annotation)含义详解
Spring boot注解(annotation)含义详解 @Service用于标注业务层组件@Controller用于标注控制层组件(如struts中的action)@Repository用于标注数 ...
- Spring boot 注解简单备忘
Spring boot 注解简单备忘 1.定义注解 package com.space.aspect.anno;import java.lang.annotation.*; /** * 定义系统日志注 ...
- 73. Spring Boot注解(annotation)列表【从零开始学Spring Boot】
[从零开始学习Spirng Boot-常见异常汇总] 针对于Spring Boot提供的注解,如果没有好好研究一下的话,那么想应用自如Spring Boot的话,还是有点困难的,所以我们这小节,说说S ...
- Spring Boot 注解之ObjectProvider源码追踪
最近依旧在学习阅读Spring Boot的源代码,在此过程中涉及到很多在日常项目中比较少见的功能特性,对此深入研究一下,也挺有意思,这也是阅读源码的魅力之一.这里写成文章,分享给大家. 自动配置中的O ...
- Spring Boot 注解的使用
Spring Boot 优于Spring mvc ,SSM,SSH 的一个亮点就是他使用了好多的注解. 1. @Autowired 这个注解的作用是将其他的类,接口引入,类似于之前的类的初始化等,用这 ...
- Spring Boot 注解详解
一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...
随机推荐
- 初涉最小表示法&&bzoj1398: Vijos1382寻找主人 Necklace
把最小表示法的坑填了 Description 给定两个项链的表示,判断他们是否可能是一条项链. Input 输入文件只有两行,每行一个由0至9组成的字符串,描述一个项链的表示(保证项链的长度是相等的) ...
- Linux用户身份(命令详解与补正)
基于Red Hat Enterprise Linux 7.5 Linux中的root就是存在于所有类UNIX系统中的超级用户,持有最高管理权限,能添加/删除用户.开关机.关闭或开启硬件或者系统服务等, ...
- find 命令search使用
GNU在目录树中查找的时候,是根据所给的名字从根节点开始从左到右匹配.根据优先级规则,直到在某一个节点找到结果了才会移动到下一个文件名字. 1.找空目录 find ./path -depth -ty ...
- Django REST framework 五种增删改查方法
Django-DRF-视图的演变 版本一(基于类视图APIView类) views.py: APIView是继承的Django View视图的. 1 from .serializers impor ...
- day12-图
- (转)ios 代码规范
转自http://blog.csdn.net/pjk1129/article/details/45146955 引子 在看下面之前,大家自我检测一下自己写的代码是否规范,代码风格是否过于迥异阅读困难? ...
- loj2003 「SDOI2017」新生舞会
分数规划+KM 算法 这个KM不好,看算法竞赛进阶指南的 #include <iostream> #include <cstring> #include <cstdio& ...
- python基础-文件和目录
字符串小练习 >>> s="1a2a3a4a5a" >>> s1=s.split('a') >>> >>> ...
- unittest编写Web测试用例
案例:百度搜索关键词:“unittest” test_baidu.py: from selenium import webdriver from time import sleep import un ...
- Redis学习笔记01---配置文件
1.配置文件用法 启动redis的时候指定配置⽂件路径: ./redis-server /path/to/redis.conf 不指定配置⽂件的时候使⽤内置配置⽂件启动,此⽅法仅适⽤于开发和测试. 2 ...