效果

实现

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. 使用Azure Congnitive Services 技术制作AI故事机

    引言 前一段时间有幸参加了微软MVP的AI方面的学习挑战赛,对于AI 这个新的领域的技术瞬间勾起了我的学习兴趣. 最近几年,不管是国内还是国外,AI都是一个异常火热的词.比如现在的自动驾驶技术,其实就 ...

  2. SpEL表达式总结(转)

    前言 SpEL(Spring Expression Language),即Spring表达式语言,是比JSP的EL更强大的一种表达式语言.为什么要总结SpEL,因为它可以在运行时查询和操作数据,尤其是 ...

  3. Javascript实现数组去重 [转]

    1.遍历数组法 它是最简单的数组去重方法(indexOf方法) 实现思路:新建一个数组,遍历去要重的数组,当值不在新数组的时候(indexOf为-1)就加入该新数组中: var arr=[2,8,5, ...

  4. vue(19)嵌套路由

    嵌套路由 有时候在路由中,主要的部分是相同的,但是下面可能是不同的.比如访问首页,里面有新闻类的/home/news,还有信息类的/home/message.这时候就需要使用到嵌套路由.项目结构如下: ...

  5. python pycharm 正则表达式批量替换

    {accept:application/json, text/plain, */*,accept-encoding:gzip, deflate, br,accept-language:zh-CN,zh ...

  6. ES6新增语法(三)——面向对象

    ES6中json的2个变化 简写:名字和值相同时,json可以可以简写 let a=12,b=5; let json = { a, b } console.log(json) // { a:12 , ...

  7. ZooKeeper 分布式锁 Curator 源码 04:分布式信号量和互斥锁

    前言 分布式信号量,之前在 Redisson 中也介绍过,Redisson 的信号量是将计数维护在 Redis 中的,那现在来看一下 Curator 是如何基于 ZooKeeper 实现信号量的. 使 ...

  8. POJ3667 Hotel 题解

    和最大子段和的思路是一样的,可以记 \(lmax,rmax,dat\) 分别表示从当前区间最靠左/右的最大连续空子段和当前区间的最大连续空子段. 需要用延迟标记,每次遇到开房操作先ask,如果能找到就 ...

  9. (java4)什么是计算机

    (java4)什么是计算机 computer : 全称电子计算机,俗称电脑 能够按照程序运行.自动.高速处理海量数据的现代化智能电子设备 由硬件和软件组成 常见的由台式计算机,笔记本计算机,大型计算机 ...

  10. C#曲线分析平台的制作(一,ajax+json前后台数据传递)

    在最近的项目学习中,需要建立一个实时数据的曲线分析平台,这其中的关键在于前后台数据传递过程的学习,经过一天的前辈资料整理,大概有了一定的思路,现总结如下: 1.利用jquery下ajax函数实现: & ...