@ApiParam @RequestParam @PathVariable 用法
文章来源:https://www.cnblogs.com/hello-tl/p/9204279.html
1.@ApiParam ,是注解api的参数 ,也就是用于swagger提供开发者文档 ,文档中生成的注释内容 。
2.@RequestParam , 是获取前端传递给后端的参数,可以是get方式,也可以是post方式。其中如果前端传递的参数和后端你接受的参数起的名字字段是一致的可以省略不写,也可以直接写@RequestParam String title,如果不一致一定要完整写,
3.@PathVariable , 获取url后面参数,进行参数绑定
package com.web.controller; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController; @RestController
@Api(value="apiTest", description="apiTest 控制器")
@RequestMapping("/apiTest")
public class ApiTestController {
// @ApiOperation 用于方法上
// @ApiParam 用于方法,参数,字段说明,表示对参数的添加元数据(说明或是否必填等) // 1.@ApiParam 是注解api的参数 ,也就是用于swagger提供开发者文档 ,文档中生成的注释内容 。
// 接受 POST 或者 GET 参数
// @ApiOperation(value = "api说明", notes = "接口发布说明", httpMethod = "请求方式 [ POST | GET ]")
@ApiOperation(value = "测试ApiOperation" , notes = "测试ApiOperation", httpMethod = "GET")
// @RequestMapping(value = "URL地址" , method = "传输方式 [ RequestMethod.GET | RequestMethod.POST] ")
@RequestMapping(value = "/ApiTest1" , method = RequestMethod.GET)
public String ApiTest1(
// @ApiParam ( name = "参数名称" , value = "api描述" , required = 是否必传[ true(必传) 接收的值 | false(非传) 默认等于 null ] ) 类型 参数绑定
@ApiParam(name = "ApiParam",value="测试ApiParam",required = true) String ApiParam){
/**
* 访问 localhost:8080/apiTest/ApiTest1
* 页面打印是空的并没有报错说 缺少ApiParam参数 这是因为 ---- ApiParam 里面 required 参数是配合 swagger-ui 用的
*
* 下伙子不要冲动---这是后可以访问一下 localhost:8080/apiTest/ApiTest2 试试
*/
return ApiParam;
} // 2.@RequestParam,是获取前端传递给后端的参数,可以是get方式,也可以是post方式。其中如果前端传递的参数和后端你接受的参数起的名字字段是一致的可以省略不写,也可以直接写@RequestParam String title,如果不一致一定要完整写
// 接受 POST 或者 GET 参数
@ApiOperation(value = "测试ApiOperation" , notes = "测试ApiOperation", httpMethod = "GET")
@RequestMapping(value = "/ApiTest2" , method = RequestMethod.GET)
public String ApiTest2(
// @RequestParam(name = "参数名称",required = "是否必传[ true(必传) | false(非传) ] 默认 true", defaultValue = "默认值") 类型 参数绑定
@ApiParam(name = "ApiParam",value="测试ApiParam",required = true)
@RequestParam(name = "ApiParam",required = true) String ApiParam){
/**
* @RequestParam(name = "ApiParam",required = false, defaultValue = "ApiParam 默认值") String ApiParam
* 访问 localhost:8080/apiTest/ApiTest2
* 会返回 ApiParam 默认值
*
* @RequestParam(name = "ApiParam",required = true) String ApiParam
* 访问 localhost:8080/apiTest/ApiTest2
* 会报错 字符串参数 ApiParam 不存在
*
* 访问 localhost:8080/apiTest/ApiTest2?ApiParam=测试地址
* 会返回 测试地址
*/
return ApiParam;
} // 3.获取url后面参数,进行参数绑定
@ApiOperation(value = "测试ApiOperation" , notes = "测试ApiOperation", httpMethod = "GET")
@RequestMapping(value = "/ApiTest3/{ApiParam}" , method = RequestMethod.GET)
public String ApiTest3(
@ApiParam(name = "ApiParam",value="测试ApiParam",required = true) @PathVariable String ApiParam){
/**
* 访问 localhost:8080/apiTest/ApiTest3
* 出返回 404
*
* 访问 localhost:8080/apiTest/ApiTest3/测试地址
* 出返回 测试地址
*/
return ApiParam;
}
}
文章来源:https://www.cnblogs.com/hello-tl/p/9204279.html
@ApiParam @RequestParam @PathVariable 用法的更多相关文章
- @RequestParam和@PathVariable用法小结
@RequestParam 使用@RequestParam接收前段参数比较方便,前端传参的URL: url = “${ctx}/main/mm/am/edit?Id=${Id}&name=${ ...
- @RequestParam和@RequestBody和@PathVariable用法小结
@RequestParam 使用@RequestParam接收前段参数比较方便,前端传参的URL: url = "${ctx}/main/mm/am/edit?Id=${Id}&na ...
- SpringMVC常用注解實例詳解1:@Controller,@RequestMapping,@RequestParam,@PathVariable
我的開發環境 框架: springmvc+spring+freemarker 開發工具: springsource-tool-suite-2.9.0 JDK版本: 1.6.0_29 to ...
- @RequestParam @PathVariable
1.Request参数 在访问各种各样网站时,经常会发现网站的URL的最后一部分形如:?xxxx=yyyy&zzzz=wwww.这就是HTTP协议中的Request参数,它有什么用呢?先来看一 ...
- SpringMVC @RequestBody @RequestParam @PathVariable 等参数绑定注解详解
request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: http://blog.csdn.net/walkerjong/article/details/794 ...
- @RequestParam,@PathVariable,@ResponseBody,@RequestBody,@ModelAttribute学习
1.@RequestParam使用于参数上,用于将请求参数映射到指定参数变量上 例如: @RequestMapping(value="/hello",method=RequestM ...
- @RequestParam,@PathVariable,@RequestBody
@RequestParam 和 @PathVariable 注解是用于从request中接收请求的,两个都可以接收参数,关键点不同的是@RequestParam 是从request里面拿取值,而 @P ...
- msql中@RequestParam、@Param、@PathVariable的用法
@RequestParam的用法 1.可以对传入参数指定参数名,将请求参数绑定至方法参数 // 下面的对传入参数指定为aa,如果前端不传aa参数名,会报错 @RequestParam(value=&q ...
- springmvc请求路径和请求参数的获取注解- @PathVariable和@RequestParam
@PathVariable和@RequestParam @PathVariable是从路径里面去获取变量,也就是把路径当做变量. @RequestParam是从请求里面获取参数. 如:url:http ...
随机推荐
- CentOS服务器下安装配置SSL
https是一个安全的访问方式,数据在传输过程中是加密的,https基于SSL. 一.安装apache和ssl模块 1.安装apache #yum install httpd 2.安装ssl模块 #y ...
- stylus基础教程,stylus实例教程,stylus语法总结
stylus特点富于表现力.具有健壮性.功能丰富.动态编码不需要写CSS的冒号.分号.大括号和LESS.SASS功能类似,会这些的入手很快stylus特点安装使用stylus语法(一)选择器(二)变量 ...
- C++ multiset通过greater、less指定排序方式,实现最大堆、最小堆功能
STL中的set和multiset基于红黑树实现,默认排序为从小到大. 定义三个multiset实例,进行测试: multiset<int, greater<int>> gre ...
- iOS Testing with Xcode 阅读笔记
官方文档直通车 Performance Testing A baseline is a combination of the average time performance in ten runs ...
- fscanf
fscanf (PHP 4 >= 4.0.1, PHP 5, PHP 7) fscanf — 从文件中格式化输入 说明 mixed fscanf ( resource $handle , str ...
- Myisamchk使用
Myisam损坏的情况: . 服务器突然断电导致数据文件损坏;强制关机,没有先关闭mysql 服务;mysqld 进程在写表时被杀掉.因为此时mysql可能正在刷新索引. . 磁盘损坏. . 服务器死 ...
- C#基础学习3
运算符,表达式!
- 严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:解决
严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal Contain ...
- 在vscode中显示空格和tab符号
转自:https://blog.csdn.net/bmzk123/article/details/86501706 使用python时最烦人的就是代码对齐,而且tab和空格还不一样,为了便于对其,希望 ...
- 分布式技术EJB3_分库架构 - 【动力节点官网】北京Java …
分布式技术EJB3_分库架构 - [动力节点官网]北京Java … http://www.bjpowernode.com/xiazai/2220.html <程序天下--EJB JPA数据库持久 ...