接口工具--Swagger

Swagger接口管理工具可方便开发测试和前后联调,集成起来也很方便。

引入依赖

<!--swagger-->
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
</dependency>
<!--swagger ui-->
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger-ui</artifactId>
</dependency>

配置类

@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket AdminapiConfig(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("管理员Api")
//               接口文档分组,过滤接口,选择-路径-正则表达式
                .apiInfo(adminApiInfo()) //自定义方法,描述展示信息
                .select()
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }
//  文档信息展示
    private ApiInfo adminApiInfo(){
        return new ApiInfoBuilder()
                .title("p2p借款平台管理员api文档")
                .description("平台管理员的api接口展示")
                .version("1.0")
                .contact(new Contact("Skiray","https://blog.csdn.net/CC1770374/","Skiray.foxmail.com"))
                .build();
    }

    @Bean
    public Docket WebapiConfig(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("普通Api")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
    }
    private ApiInfo webApiInfo(){
        return new ApiInfoBuilder()
                .title("p2p借款平台普通用户api文档")
                .description("平台普通用户的api接口展示")
                .version("1.0")
                .contact(new Contact("Skiray","https://blog.csdn.net/CC1770374/","Skiray.foxmail.com"))
                .build();
    }
}

接口

@Api(tags = "积分管理")
@CrossOrigin //允许跨域请求,测试用
@RestController
@RequestMapping("admin/core/integralGrade")
public class AdminIntegralGradeController {

    @Resource
    private IntegralGradeService integralGradeService;

    @ApiOperation("获取积分列表")
    @GetMapping("/list")
    public List<IntegralGrade> listAll(){
        return integralGradeService.list();
    }

    @ApiOperation(value = "根据id删除积分数据", notes = "逻辑删除积分记录")
    @DeleteMapping("remove/{id}")
    public boolean deleteById(
            @PathVariable
            @ApiParam(value = "数据id",example = "100",required = true)
                    Long id ){
        return integralGradeService.removeById(id);
    }

}

注解

实体类

@ApiModel(value = "" ,description = "") // 实体类名称


@ApiModelProperty(value = "",example = " ") //实体类性名

Controller

@Api(tags = "") //接口的名称描述 ,以单个Controller文件为一组

@ApiOperation(value = "根据id删除积分数据", notes = "逻辑删除积分记录")//单个接口的描述

@ApiParam(value = "数据id",example = "100",required = true) //接口参数描述

展示

img

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值