效果

实现

SwaggerAutoConfiguration里新增配置:

package com.fxkj.common.config;

import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; /**
* @author Jackson
*/
@Profile({"default", "dev", "test"})
@Configuration
@EnableConfigurationProperties({SwaggerProperties.class})
@ConditionalOnProperty(prefix = "swagger",value = "enable")
@EnableSwagger2
public class SwaggerAutoConfiguration {
@Resource
private SecurityConfig securityConfig; @Bean
public Docket swaggerSpringMvcPlugin(@Autowired SwaggerProperties swaggerConfigProps) {
return new Docket(DocumentationType.SWAGGER_2)
.enable(swaggerConfigProps.isEnable())
.useDefaultResponseMessages(false)
.apiInfo(apiInfo(swaggerConfigProps))
.securitySchemes(getSecuritySchemes())
.securityContexts(getSecurityContexts())
.select()
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
} private ApiInfo apiInfo(SwaggerProperties properties) {
return new ApiInfoBuilder()
.title(properties.getTitle())
.version(properties.getVersion())
.description(properties.getDescription())
.contact(new Contact(properties.getContactName(),
properties.getContactUrl(),
properties.getContactEmail()))
.license("Apache License Version 2.0")
.licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
.version("2.0")
.build();
} @Bean
public Docket api_system(@Autowired SwaggerProperties swaggerConfigProps) {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfoSystem(swaggerConfigProps))
.securitySchemes(getSecuritySchemes())
.securityContexts(getSecurityContexts())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/system/**"))
.build()
.groupName("系统设置")
.pathMapping("/");
} @Bean
public Docket api_role(@Autowired SwaggerProperties swaggerConfigProps) {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfoSystem(swaggerConfigProps))
.securitySchemes(getSecuritySchemes())
.securityContexts(getSecurityContexts())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/roles/**"))
.build()
.groupName("角色设置")
.pathMapping("/");
} @Bean
public Docket api_dict(@Autowired SwaggerProperties swaggerConfigProps) {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfoSystem(swaggerConfigProps))
.securitySchemes(getSecuritySchemes())
.securityContexts(getSecurityContexts())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/dict/**"))
.build()
.groupName("字典维护")
.pathMapping("/");
} private ApiInfo apiInfoSystem(SwaggerProperties properties) {
return new ApiInfoBuilder()
.title("系统设置相关API")
.version(properties.getVersion())
.description(properties.getDescription())
.contact(new Contact(properties.getContactName(),
properties.getContactUrl(),
properties.getContactEmail()))
.license("Apache License Version 2.0")
.licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
.version("2.0")
.build();
} private ArrayList<ApiKey> getSecuritySchemes() {
return Lists.newArrayList(
new ApiKey("token", "token", "header")
);
} private List<SecurityContext> getSecurityContexts() {
AuthorizationScope[] scopes = {
new AuthorizationScope("global", "accessEverything")
};
List<SecurityReference> securityReferences = Lists.newArrayList(
new SecurityReference("token", scopes)
);
return Lists.newArrayList(SecurityContext.builder()
.securityReferences(securityReferences)
.forPaths(Predicates.not(Predicates.in(securityConfig.getIgnoreUrls())))
.build());
}
}

  

swagger菜单分级的更多相关文章

  1. python学习入门第一天总结

    虽然之前自己也看过许多关于python的视频,但一直没有动力与勇气,所以未能坚持且也没有学得这么深刻,这次希望通过python自动化培训,能够彻底改变自己,通过第一天的python学习,自己学到了许多 ...

  2. 我的第一个python web开发框架(34)——后台管理系统权限设计

    框架底层和接口终于改造完成了,小白再次找到老菜. 小白:老大,上次你对后台权限系统简单的讲了一下,我一点头绪都没有,现在有空完整的说一说吗? 老菜:说到权限系统,要讲明白真不容易,权限系统并不是越复杂 ...

  3. Django框架----权限管理(设计分析以及具体细节)

    说起权限我们大家都知道,不一样的角色会有不一样的权限.比如就像学生管理系统一样,管理员,老师,学生之间的权限都是不一样的,那么展示的页面也是不一样的.所以,我们现在来看看具体操作. 目标:生成一个独立 ...

  4. 基于角色权限管理:rbac设计分析以及具体细节

    权限管理---设计分析以及具体细节 说起权限我们大家都知道,不一样的角色会有不一样的权限. 比如就像学生管理系统一样,管理员,老师,学生之间的权限都是不一样的,那么展示的页面也是不一样的. 所以,我们 ...

  5. jQuery知识点小结

    博主之前学习一段时间后做了点Demo,借此机会发出来分享,其实学jQuery只要简单看看文档即可,但有些细枝末节的东西文档会默认使用者是了解的,所以还是得系统学习系统训练:Talk is cheap, ...

  6. 基于react实现无限分级菜单

    在开发CMS(内容管理系统)系统时,一般都会用到一个侧边栏或者顶部的二级或者三级菜单,当点击或者鼠标悬浮时,菜单能够随之展开或收起. 本文纯粹为了练习一下react,因此我会在react环境下实现这么 ...

  7. JS及Dom示例 | 分级菜单折叠

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. jQuery示例 | 分级菜单

    <!DOCTYPE html> Title .header{ background-color: black; color: wheat; } .content{ min-height: ...

  9. 无限分级和tree结构数据增删改【提供Demo下载】

    无限分级 很多时候我们不确定等级关系的层级,这个时候就需要用到无限分级了. 说到无限分级,又要扯到递归调用了.(据说频繁递归是很耗性能的),在此我们需要先设计好表机构,用来存储无限分级的数据.当然,以 ...

随机推荐

  1. Java实验项目二——二维数组实现九九乘法表

    Program:打印乘法口诀表 (1)编写一个方法,参数(二维数组),完成将二维数组中的数据按照行列显示的工作. (2)编写一个测试方法,给出99乘法表,放入到二维数组中,调用(1)中的方法,显示乘法 ...

  2. Jmeter之代理元件&代理配置

    一 jmeter代理服务器添加及网页代理配置 1.1 打开jmeter,添加代理HTTP代理服务器,再添加一个线程组,放在代理服务器的下面. 1.2 代理服务器设置 端口默认8888,目标控制器选择t ...

  3. EXCEL中的多个条件同时成立写法

    =IF(AND($B2>0,$C2>0,$D2>0,$E2>0),(($B2*1000/$C2/60/$D2)*$E2),0)点击F2,粘贴上边的公式选择F2到f200ctrl ...

  4. css列表属性和样式控制

    如下图是360浏览器主页的内容,上边有导航,下边是新闻列表,这种布局很常见,今天就来学习css列表属性之后并制作它. 列表属性 html有三种类型的列表:无序列表,有序列表和自定义列表.设置列表标记有 ...

  5. BiPredicate的test()方法

    /** * BiPredicate的test()方法接受两个参数,x和y,具体实现为x.equals(y), * 满足Lambda参数列表中的第一个参数是实例方法的参数调用者,而第二个参数是实例方法的 ...

  6. Pytest单元测试框架之parametrize参数化

    1.参数化的本质:相同的步骤,但测试数据不同,比如登录的场景 import mathimport pytest# 方式一:分离出Listdef list_Test(): list = [ [2, 2, ...

  7. Python 数值中的下划线是怎么回事?

    花下猫语:Python 中下划线的用法令人叹为观止,相信你已在各种文章或教程中见识过了.在 2016 年的 3.6 版本之后,Python 还引入了一种新的语法,使得下划线也可以出现在数值中.这篇翻译 ...

  8. windows 10家庭版安装SQL Server 2014出现.net 3.5失败问题解决。

    在安装SQL Server 2014的过程中,出现.net 3.5缺失,导致失败问题. 后来,研究了下,解决思路如下: 先将电脑更新到了windows 10专业版,(因为需要用到专业版才有的组策略管理 ...

  9. 大数据学习(08)—— Hive简介

    前面的Hadoop学习是非常体系化的,有主线有细节.到了Hive这里,知识点非常零散,感觉没有什么主线能把它串起来.从官方网站上就能看出这点差异. 什么是Hive Hive是一个基于Hadoop的企业 ...

  10. Ming Yin(@kalasoo)在知乎的几个回答 : 观点犀利

    这篇文章汇总了掘金前站长Ming Yin(阴明)在知乎的几个犀利的观点,原文可访问zhihu.com/kalasoo 由@flightmakers转载(收藏)在此 你是否有个人网站.可否和大家分享一下 ...