java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Swagger的使用

Java中Swagger框架的使用详解

作者:余生海

这篇文章主要介绍了Java框架Swagger的使用详解,在开发期间接口会因业务的变更频繁而变动,如果需要实时更新接口文档,这是一个费时费力的工作,Swagger应运而生,他可以轻松的整合进框架并通过一系列注解生成强大的API文档,需要的朋友可以参考下

简介

常用注解

代码示例

@Api(value = "用户博客", tags = "博客接口")
public class NoticeController {
}
@GetMapping("/detail")
@ApiOperation(value = "获取用户详细信息", notes = "传入notice")
public R<Notice> detail(Integer id) {
   Notice detail = noticeService.getOne(id);
   return R.data(detail );
}
@GetMapping("/detail")
@ApiOperation(value = "获取用户详细信息", notes = "传入notice")
@ApiResponses(value = {@ApiResponse(code = 500, msg= "INTERNAL_SERVER_ERROR", response = R.class)})
public R<Notice> detail(Integer id) {
   Notice detail = noticeService.getOne(id);
   return R.data(detail );
}
@GetMapping("/list")
@ApiImplicitParams({
   @ApiImplicitParam(name = "category", value = "公告类型", paramType = "query", dataType = "integer"),
   @ApiImplicitParam(name = "title", value = "公告标题", paramType = "query", dataType = "string")
})
@ApiOperation(value = "分页", notes = "传入notice")
public R<IPage<Notice>> list(@ApiIgnore @RequestParam Map<String, Object> notice, Query query) {
   IPage<Notice> pages = noticeService.page(Condition.getPage(query), Condition.getQueryWrapper(notice, Notice.class));
   return R.data(pages );
}
@PostMapping("/remove")
@ApiOperation(value = "逻辑删除", notes = "传入notice")
public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
   boolean temp = noticeService.deleteLogic(Func.toIntList(ids));
   return R.status(temp);
}
@Data
@ApiModel(value = "BladeUser ", description = "用户对象")
public class BladeUser implements Serializable {
   private static final long serialVersionUID = 1L;
   @ApiModelProperty(value = "主键", hidden = true)
   private Integer userId;
   @ApiModelProperty(value = "昵称")
   private String userName;
   @ApiModelProperty(value = "账号")
   private String account;
   @ApiModelProperty(value = "角色id")
   private String roleId;
   @ApiModelProperty(value = "角色名")
   private String roleName;
}
@ApiIgnore()
@GetMapping("/detail")
public R<Notice> detail(Integer id) {
   Notice detail = noticeService.getOne(id);
   return R.data(detail );
}

到此这篇关于Java中间件Swagger的使用详解的文章就介绍到这了,更多相关Swagger的使用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文