效果

实现

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. 修改myeclipse 项目中用的jdk版本

    修改myeclipse 项目中用的jdk版本 首先, 打开MyEclipse,如下图所示 打开之后,找到我们的java项目 右键--"Build Path--->Confirgure ...

  2. XCTF simple js

    思路分析: 进入靶场, 随便输入,肯定是错误的,f12看下源码,结合题目说js,把js代码单独拿出来看看. function dechiffre(pass_enc){ var pass = " ...

  3. buu RSA

    一.分析 下载链接,发现一个公钥的文件(e,n),和一个加密过的文件 二. 公钥文件,里面一堆字母,然后后面百度,才知道需要去解开n,e 指数是e,模数是n(十六进制) 三.再通过n来分解素数,得到p ...

  4. 小程序textarea设置maxlength后不是你想的那样简单

    可能很多小伙伴们.看见这个标题后; 觉得作者是一个标题党. textarea设置maxlength后, 限制用户输入的字符呗! 还能怎么样呢? 恭喜你,说对了一半. 之前我也一直是这样想的. 知道今天 ...

  5. Java | Map集合

    Map集合 在现实生活中,有非常多的东西,是和另外一种东西对应的,并且还是唯一的,比如:身份证号与个人,个人与手机,一夫一妻...等,这种关系就是对应关系,又叫做映射.Java为这种数据类型提供了专门 ...

  6. c语言:逗号运算符

    #include <stdio.h> main() { int a,s,d; s=2,d=3; a=12+(s+2,d+4); printf("%d\n",a); in ...

  7. Ajax爬取动态数据和HTTPS自动默认证书

    Ajax数据爬取 在spider爬取数据的过程中,有些网页的数据是利用Ajax动态加载出来的,所以,在网页源代码中可能不会看到这一部分的数据,因此,我们需要使用另外的方式进行数据多爬取. 以豆瓣电影的 ...

  8. HTML5-CSS(三)

    一.CSS  盒模型 1.元素尺寸:CSS 盒模型中最基础的就是设置一个元素的尺寸大小.有三组样式来配置一个元素的尺寸大小,样式表如下 //设置元素尺寸 div { width: 200px;heig ...

  9. 微信小程序云开发-云存储的应用-识别身份证(正面和反面)

    一.准备工作 1.创建云函数identify 2.云函数identify中index.js代码 1 // 云函数入口文件 2 const cloud = require('wx-server-sdk' ...

  10. 扩展中国剩余定理(exCRT)

    我 tm--CRT 没看懂 exCRT 却看懂了--emmmm-- 而且这名字完全就是国内的 OI 带师胡起的吧-- 考虑一次同余方程组 \[\begin{cases} x \equiv a_1\ ( ...