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三者区别的更多相关文章

  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. 初涉k-d tree

    听说k-d tree是一个骗分的好东西?(但是复杂度差评??? 还听说绍一的kdt常数特别小? KDT是什么 KDT的全称是k-degree tree,顾名思义,这是一种处理多维空间的数据结构. 例如 ...

  2. 【Java_多线程并发编程】基础篇——线程状态扭转函数

    1. wait() sleep() yield() join()用法与区别 本文提到的当前线程是指:当前时刻,获得CPU资源正在执行的线程. 1.1 wait()方法 wait()方法定义在Objec ...

  3. 利用Resttemplate进行put请求

    开发中,最常用的是post.get这两种.今天我给大家展示一个利用put请求的demo,其实put请求跟post请求没啥区别,但是没有返回值. void put(String var1, @Nulla ...

  4. perl学习之:理解贪婪匹配和最小匹配之间的区别

    正则表达式的新手经常将贪婪匹配和最小匹配理解错误.默认情况下,Perl 的正则表达式是“贪婪地”,也就是说它们将尽可能多地匹配字符. 下面的脚本打印出“matched defgabcdef”,因为它尽 ...

  5. python安装numpy模块

    1.打开网址https://pypi.python.org/pypi/numpy,找到安装的python版本对应的numpy版本. 我的python版本是 下载的对应numpy版本是 2.将numpy ...

  6. python--类的约束, 异常处理, MD5, 日志处理

    一 . 类的约束 1. 写一个父类,父类中的某个方法要抛出一个异常 NotImplementedError class Base: # 对子类进行了约束. 必须重写该方法 # 以后上班了. 拿到公司代 ...

  7. nrf52832开发配置文件小记

    nrf52832在配置定时器和port事件的时候,需要在nrf_drv_config.h(sdk12.x.0版本)文件中,将相应的使能,比如:#define TIMER0_ENABLED 1否则,是不 ...

  8. bash中的算术运算

    bash中的算术运算     +, -, *, /, %     实现算术运算:         (1) let var=算术表达式          (2) var=$[算术表达式]         ...

  9. 图论trainning-part-1 E. Invitation Cards

    E. Invitation Cards Time Limit: 8000ms Memory Limit: 262144KB 64-bit integer IO format: %lld      Ja ...

  10. Neural Networks and Deep Learning

    Neural Networks and Deep Learning This is the first course of the deep learning specialization at Co ...