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. PAT 乙级 1027

    题目 题目地址:PAT 乙级 1027 思路 本题需要注意两点: 1. 对于每行输出字符的循环和判断没有完全搞清楚,导致在4 * 的条件下会输出7个字符,n的结果是-3. 2. 没有考虑到小于等于0的 ...

  2. POJ-2251-地下城

    这题是一道简单的广搜题目,读入的时候,需要注意,如果是用scanf读入的话,就直接读取每行的字符串,不然的话,行尾的回车,也会被当成字符读入,这样的话,每次读取的数目就会小于我们想要的数目,因为每次把 ...

  3. (转) [C++]我再也不想在任何头文件中看到using namespace xxx这种句子了(译)

    原文的传送:I don’t want to see another “using namespace xxx;” in a header file ever again 转自  http://blog ...

  4. ZZULIoj 1912 小火山的爱情密码

    Description 小火山获得了一个字符串,然而大火山让小火山从里面截取一段字符串,并且让小火山截取的字符串满足一些字符达到一定数量. 小火山觉得很容易,但是他想要知道他至少得截取多长的字符串. ...

  5. iOS8 WebKit库之——WKWebView篇

    iOS8 WebKit库之--WKWebView篇 webkit使用WKWebView来代替IOS的UIWebView和OSX的WebView,并且使用Nitro JavaScript引擎,这意味着所 ...

  6. Window Phone 8手电筒

    一直想开发一个Wp8的手电筒程序,看了好多别人开发的基本上有以下问题: 1.锁屏闪光灯关闭了 2.闪光灯不停的闪烁. 我就想开发一个锁屏也能用的手电筒,发现找资料那是相当的困难.找到的代码基本都不能令 ...

  7. kali-xfce的简单配置

    1.更新 设置kali的更新源 在终端中打开sources.list root@kali:~# vim /etc/apt/sources.list 删除里面的注释,清空. 然后输入下面的更新源地址: ...

  8. Python内置函数6

    Python内置函数6 1.license() 输出当前python 的license信息 A. HISTORY OF THE SOFTWARE ========================== ...

  9. .net提高文章

    文章:.NET程序性能的基本要领 文章:你的字典里有多少元素? 文章:快速自检电脑是否被黑客入侵过(Windows版) 文章:关于DNS,你应该知道这些

  10. 九度oj 题目1345:XXX定律之画X

    题目描述: 给你一个n,然后让你输出F(n)规则是这样的,F(n)的输出结果是:F(n-1)     F(n-1)       F(n-1) F(n-1)      F(n-1) F(1)的输出结果是 ...