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#/