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. js之数组知识

    一.数组的定义(来源于Array.prototype) 1.构造函数方法: (1)var arr = new Array();//没有参数等价于 var arr = []; (2)var arr = ...

  2. 【二分】bestcoder p1m2

    模型的转化和二分check的细节挺不错的 Problem Description 度度熊很喜欢数组!! 我们称一个整数数组为稳定的,若且唯若其同时符合以下两个条件: 数组里面的元素都是非负整数. 数组 ...

  3. __new__.py

    def func(self): print('hello %s' %self.name)def __init__(self,name,age): self.name = name self.age = ...

  4. DocDokuPLM 2.5安装

    安装记录:(大部分是环境安装和配置) 未完待续.

  5. 初中级PHP面试基础汇总

    这是我整理的一套面试题,老铁们看看就当复习了哦 相关PHP面试题 搞定PHP面试 - 函数知识点整理 php 面试题目整理 PHP面试整理 PHP面试 概述 感觉现在发面试题有些冷门,就跟昨天德国那场 ...

  6. Eclipse截取android报错log

    Eclipse截取android报错log: 1.前提条件:已安装eclipse 2. LogCat界面设置: Logcat是Android 编程中一个命令行工具,可以用于得到程序的 log 信息,可 ...

  7. appium之toast处理

    注意 toast要appium1.6.3以上版本才支持,Android 5.0以上(需使用夜神多开模拟器),jdk1.8且配置了环境变量. toast定位 1.先看下toast长什么样,如下图,像这种 ...

  8. A. Test for Job

    A. Test for Job Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB   64-bit integer IO ...

  9. enable apache2 rewrite_mod on ubuntu14.04

    $ cd /etc/apache2/mods-enable $ ln -s rewrite.load ../mods-available/rewrite.load change "Allow ...

  10. ubuntu14.04 Cannot find OpenSSL's <evp.h>

    Cannot find OpenSSL's <evp.h> when i configure php7 manually,i get trouble with that problem,f ...