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. CF547D Mike and Fish 建图

    题意: 有点长→CF547DMike and Fish. 分析: 其实也没什么好分析的,我这也是看的题解. (不过,那篇题解好像文字的代码不太对劲) 这里直接说做法,正确性自证: 对输入的,将横.纵坐 ...

  2. PWA天气应用

    https://codelabs.developers.google.com/codelabs/your-first-pwapp/#0 1.介绍 这里将使用PWA技术来构建一个天气web应用,这个ap ...

  3. tensorboard以时间命名每一个文件夹

    tensorboard 有一个良好的命名习惯以时间命名每一个文件夹,例如**20190523_081232** ''' from datetiome import datetime dir = os. ...

  4. Java-改变Class

    改变一个Class对象的类型 package com.tj; public class MyClass2 { public static void main(String[] args) { Obje ...

  5. Fiddler-给手机设置代理并抓取https链接

    注:有两部分fiddler设置和手机端设置,且配置完成后,使用时确保PC和手机连接同一WiFi 设置方法如下: 1.上网搜索fiddler官方版下载,并安装完成后,开启fiddler 2.选择Tool ...

  6. Python内置函数5

    Python内置函数5 1.format参考前面字符串方法中的format 2.frozenset([iterable]) iterable -- 可迭代的对象,比如列表.字典.元组等等 返回一个冻结 ...

  7. PHP “引号兄弟”

    PHP的string最大可以达到2GB,不过很少会用到这么大的字符串. 单引号: 定义一个字符串最简单的方式是使用单引号,而在单引号字符串中要想表达一个单引号,需要在她的前面加个反斜线(\)来进行转义 ...

  8. NYOJ 814 又见拦截导弹

    又见拦截导弹 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦 ...

  9. JSPatch安全部署

    前言 这个事JSPatch集成到客户端的第二篇,第一篇链接:http://www.cnblogs.com/hxwj/p/5163158.html 安全部署链接:http://blog.cnbang.n ...

  10. HDU 1423 Greatest Common Increasing Subsequence ——动态规划

    好久以前的坑了. 最长公共上升子序列. 没什么好说的,自己太菜了 #include <map> #include <cmath> #include <queue> ...