swagger2如何配置

pom.xml文件
添加依赖

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.4.0</version>
    </dependency>

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

Util类
package com.jxjy.common;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
*

  • 集成Swagger2的页面配置
    */
    //@Configuration //这里需要注意,如果项目架构是SSM,那就不要加这个注解,如果是 spring boot 架构类型的项目,就必须加上这个注解,让 spring 加载该配置。
    @EnableWebMvc // spring boot 项目不需要添加此注解,SSM 项目需要加上此注解,否则将会报错。
    @EnableSwagger2
    public class SwaggerConfig {
    @Bean
    public Docket buildDocket(){
    return new Docket(DocumentationType.SWAGGER_2)
    .apiInfo(buildApiInfo())
    .select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))// controller路径。
    .paths(PathSelectors.any())
    .build();
    }
    // 配置 API 文档标题、描述、作者等等相关信息。
    private ApiInfo buildApiInfo(){
    return new ApiInfoBuilder()
    .title(“继续教育项目接口文档”)
    .termsOfServiceUrl("")
    .description(“继续教育项目接口文档”)
    .version(“1.0”)
    .build();
    }
    }
    在shiro.xml设置



    /images/=anon
    /js/
    =anon
    /style/=anon

    /swagger-ui.html=anon
    /swagger-resources=anon
    /v2/api-docs=anon
    /webjars/
    = anon
    /swagger/=anon
    /configuration/
    =anon

    /druid = anon
    /logout = logout

    /**=anon


    Controller层类上
    @Api(tags = “导入模板”)
    @RestController
    @RequestMapping("/export")
    public class ExportController {

Controller 层方法上
@ApiOperation(value = “教师导入模板”)
@GetMapping("/downloadTc")
@RequiresPermissions(“export:downloadTc”)
然后访问就可以测试数据
http://localhost:8080/swagger-ui.html#/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值