springcloud-swagger接口文档

pom.xml

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

com.jwxt.entity.academic.Exam
	 	@Data
		@NoArgsConstructor
		@AllArgsConstructor
		@Builder
		@ToString
		@TableName("st_exam")
		@ApiModel(value = "com.jwxt.entity.academic.Exam",description = "试卷实体类")
			public class Exam implements Serializable {
			
	  @TableId(type = IdType.ID_WORKER_STR)
	  @ApiModelProperty(value = "ID")
	  private String id;
	
	  @TableField("exam_name")
	  @ApiModelProperty(value = "试卷名称")
	  private String examName;
	
	  @TableField("class_id")
	  @ApiModelProperty(value = "班级ID")
	  private String classId;
	
	  @TableField("class_name") //算出来的
	  @ApiModelProperty(value = "班级名称")
	  private String className;
	
	  @TableField("person_number") //算出来的
	  @ApiModelProperty(value = "班级人数")
	  private Integer personNumber;
	
	  @TableField("exam_time")
	  @ApiModelProperty(value = "开考时间")
	  private Date examTime;
	
	  @TableField("exam_time_length")
	  @ApiModelProperty(value = "考试时长")
	  private Integer examTimeLength;
	
	  @TableField("exam_type")
	  @ApiModelProperty(value = "试卷类型 1日测 2周测 3月考")
	  private String examType;  //1日测 2周测 3月考
	
	  @TableField("single_count")
	  @ApiModelProperty(value = "单选题数量")
	  private Integer singleCount;
	
	  @TableField("single_score")
	  @ApiModelProperty(value = "单选题每题分数")
	  private Integer singleScore;
	
	  @TableField("single_joins")
	  @ApiModelProperty(value = "单选题ID组")
	  private String singleJoins; //算出来的
	
	  @TableField("mutiple_count")
	  @ApiModelProperty(value = "多选题数量")
	  private Integer mutipleCount;
	
	  @TableField("mutiple_score")
	  @ApiModelProperty(value = "多选题每题分数")
	  private Integer mutipleScore;
	
	  @TableField("mutiple_joins")
	  @ApiModelProperty(value = "多选题ID组")
	  private String mutipleJoins;//算出来的
	
	  @TableField("ask_count")
	  @ApiModelProperty(value = "问答题数量")
	  private Integer askCount;
	
	  @TableField("ask_score")
	  @ApiModelProperty(value = "问答题每题分数")
	  private Integer askScore;
	
	  @TableField("ask_joins")
	  @ApiModelProperty(value = "问答题ID组")
	  private String askJoins;//算出来的
	
	  @TableField("upper_count")
	  @ApiModelProperty(value = "上机题数量")
	  private Integer upperCount;
	
	  @TableField("upper_score")
	  @ApiModelProperty(value = "上机题每题分数")
	  private Integer upperScore;
	
	  @TableField("upper_joins")
	  @ApiModelProperty(value = "上机题ID组")
	  private String upperJoins;//算出来的
	
	  @TableField("exam_status")
	  @ApiModelProperty(value = "试卷状态 1未开始 2进行中 3批阅中 4已结束")
	  private String examStatus;//后台填写
	
	  @TableField("modify_time")
	  @ApiModelProperty(value = "操作时间")
	  private Date modifyTime;  //后台填写
	
	  @TableField("modify_name")
	  @ApiModelProperty(value = "操作人")
	  private String modifyName;//后台填写
	
	  @TableField(exist = false)
	  @ApiModelProperty(value = "章节ID组(传递)")
	  private String[] chapterIdsArray; //(传递)
	
	  @TableField("chapter_ids")
	  @ApiModelProperty(value = "章节ID组(存储)")
	  private String chapterIds;//章节id组 ,号拼接(存储)
	
	  @TableField(exist = false)//(传递)
	  @ApiModelProperty(value = "试卷题型id组(传递)")
	  private String [] questionTypeIdsArray;
	
	  @TableField("question_type_ids")
	  @ApiModelProperty(value = "试卷类型id组(存储)")
	  private String questionTypeIds;   //(存储)试题类型 以,号拼接  1单选题2多选题3问答题4上机题
	
	}

application.yml

eureka:
    instance:
        status-page-url: http://${spring.cloud.client.ip-address}:${server.port}/swagger-ui.html

swagger:
  authorization:
    key-name: token

SwaggerConfig,java

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket userApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.jwxt"))//过滤的接口
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("eureka服务端提供者接口平台").description("服务相关数据接口")
                .termsOfServiceUrl("韩志彬").contact("北大青鸟-技术研发部")
                .license("Licence Version 1.0").licenseUrl("#").version("1.0").build();
    }

}

com.jwxt.exam.controller.StudentExamController

@RestController
@RequestMapping("/exam/")
@Api(value = "学生考试接口")
public class StudentExamController extends BaseController {

    @Autowired
    private StudentExamService studentExamService;

    @RequestMapping(value = "/getList",method = RequestMethod.POST,name = "API-STUDENT-EXAM-LIST")
    @ApiOperation(value = "试卷列表",notes = "获取学生试卷列表")
    public Result getList(@ApiParam(value = "查询试卷列表参数") @RequestBody Map<String,Object> map) throws CommonException {
        map.put("userId", JwtUtils.getClaims(request).getId());
        return studentExamService.getList(map);
    }
}

com.jwxt.DocumentationConfig

package com.jwxt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Component
@EnableSwagger2
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider  {

    @Autowired
    private DiscoveryClient discoveryClient;

    @Value("${spring.application.name}")
    private String applicationName;


    @Override
    public List<SwaggerResource> get() {
        List<SwaggerResource> resources = new ArrayList<>();
        // 排除自身, 将其他的服务添加进去
        discoveryClient.getServices().stream().filter(s -> !s.equals(applicationName)).forEach(name -> {
            resources.add(this.swaggerResource(name, "/" + name + "/v2/api-docs", "2.0"));
        });
        return resources;
    }

    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值