前言:
@Api,@ApiOperation,@ApiImplicitParam,@ApiModelProperty
正文:
1,Controller层
@CrossOrigin(origins = "*")
@RestController
@Api(tags= {"文章接口"})public classArticleController {
@ApiOperation(value= "文章详情")
@ApiImplicitParams({
@ApiImplicitParam(name= "id", value = "文章编号", required = true, dataType = "String", paramType = "query"),
})
@RequestMapping(value= "article", method =RequestMethod.GET)public ResultgetArticleInfo(String id) {return this.theService.getArticleInfo(id);
}
}
@Api:作用在类上,用来标注该类具体实现内容。
参数:
1,tags:该类的名称
2,description:描述该类的作用
@ApiOperation:表示一个http请求的操作
参数:
1,value : 接口名称
@ApiImplicitParam:接口的单个请求参数
参数:
1,name :参数名
2,value : 描述参数名
3,required : 该参数是否必填
4,dataType :参数的数据类型
5, paramType :查询参数类型,可不填。这里有几种形式:
类型
作用
path
以地址的形式提交数据
query
直接跟参数完成自动映射赋值
body
以流的形式提交 仅支持POST
header
参数在request headers 里边提交
form
以form表单的形式提交 仅支持POST
2,如果传入的参数是用实体类接收的
public classAddVo {
@ApiModelProperty(name="province", value="所在省", required=true)privateString province;
@ApiModelProperty(name="city", value="所在市", required=true)privateString city;
}
@ApiModelProperty:同@ApiImplicitParam一致
参考博客: