Swagger接口管理工具可方便开发测试和前后联调,集成起来也很方便。
引入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<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 = "")
@ApiOperation(value = "根据id删除积分数据", notes = "逻辑删除积分记录")
@ApiParam(value = "数据id",example = "100",required = true)
展示