swagger中接口注释Get请求
两种方式:
方式一:
这里注意需要加上一个dataType指明参数类型不然swagger就会默认为string类型
@GetMapping("/app-anon/station")
@ApiOperation(value = "下拉列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "type", value = "选者下拉:1-所属分台下拉 2-任务Ip下拉", required = true),
@ApiImplicitParam(name = "port", value = "是否app:true(是),其他就不是",dataType = "Boolean"),
})
public Result<List<PublicVO>> getAppList(@NotNull @RequestParam("type") String type,@RequestParam(value = "port",required = false)Boolean port) {
return new Result<>(bksStationMaterialService.getAppList(type,port));
}
方式二
@GetMapping("/app-anon/station")
@ApiOperation(value = "下拉列表")
public Result<List<PublicVO>> getAppList(@NotNull @ApiParam("选者下拉:1-所属分台下拉 2-任务Ip下拉") @RequestParam(required = true) String type,
@ApiParam("是否app:true(是),其他就不是")@RequestParam(required = false)Boolean port) {
return new Result<>(bksStationMaterialService.getAppList(type,port));
}
注意这里是用@RequestParam前端就必须拼接到接口上,因为swagger会校验参数,所以不想让前端传参的时候就不能加这个注解,但是需要注解表示这个字段名称可以加@ApiImplicitParam这个注解
@GetMapping("/list")
@ApiOperation(value = "关注企业的列表")
@ApiImplicitParam(name = "companyName", value = "企业名称")
public Result<PageVO<FollowCompanyVO>> listCompany(PageInfo info, String companyName) {
return new Result<>(memberCompanyService.listCompany(info, companyName));
}
swagger注解
实体类中的注解使用@Valid 或者@Validated
在实体类中使用 @NotBlank注解标注不能为空,这里需要注意引入的包如下图