栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot介入Swagger 2.0完善 生成接口文档生成,接口测试 SwaggerFox模式的

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot介入Swagger 2.0完善 生成接口文档生成,接口测试 SwaggerFox模式的

SpringBoot介入Swagger 2.0完善 生成接口文档生成,接口测试 SwaggerFox模式的 1. 搭建Swawgger2环境(添加依赖)

        
            io.springfox
            springfox-swagger2
            2.8.0
        
        
            io.springfox
            springfox-swagger-ui
            2.8.0
        
2. 配置类
@Configuration//创建配置类的注解
@EnableSwagger2//打开支持Swagger2
public class SwaggerConfig {
      @Bean
      public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .pathMapping("/")//访问的路径
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.example"))//扫描注解包所在的位置
                    .paths(PathSelectors.any())
                    .build().apiInfo(new ApiInfoBuilder()
                            .title("智慧景区公共信息云平台后台服务接口列表")//接口大标题
                            .description("服务中心,运营中心等相关接口说明...")//接口说明
                            .version("2.1")//版本号
                            .contact(new Contact("大老板","blog.csdn.net","aaa@gmail.com"))
                            .license("China dci")
                            .licenseUrl("http://www.chinadci.com")
                            .build());
      }
}
3. 接口中的
@RestController
@Api(tags = "学生的接口")//接口类的说明
public class StudentController {

      @ApiOperation(value = "查询学生的信息")//接口说明
      @GetMapping("SelectStudent")
      public Object SelectStudent(){
            return "查询学生..............";
      }

      @PostMapping("InsertStudent")
      @ApiOperation(value = "添加学生")//接口说明
      @ApiImplicitParams(//接口参数说明
              {
                      @ApiImplicitParam(name = "name", value = "学生名字"),
                      @ApiImplicitParam(name = "pwd", value = "学生密码")
              }
      )
      public Object InsertStudent(String name,String pwd){
            return "添加学生..............";
      }
}

4. 实体类
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "学生的Model")//实体类的说明
public class Student {
      @ApiModelProperty(value = "学生id")//字段说明
      private Integer id;
      @ApiModelProperty(value = "学生姓名")//字段说明
      private String name;
      @ApiModelProperty(value = "学生密码")//字段说明
      private String pwd;
}
5. 启动后 访问 http://localhost:8080/swagger-ui.html
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/891589.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号