1.添加依赖

<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>

2.配置类

package com.cj.system.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; import java.util.ArrayList;
import java.util.List; @Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {
@Bean
public Docket adminApiConfig(){
List<Parameter> pars = new ArrayList<>();
ParameterBuilder tokenPar = new ParameterBuilder();
tokenPar.name("token")
.description("用户token")
.defaultValue("")
.modelRef(new ModelRef("string"))
.parameterType("header")
.required(false)
.build();
pars.add(tokenPar.build());
//添加head参数end Docket adminApi = new Docket(DocumentationType.SWAGGER_2)
.groupName("adminApi")
.apiInfo(adminApiInfo())
.select()
//只显示admin路径下的页面
.apis(RequestHandlerSelectors.basePackage("com.cj"))
.paths(PathSelectors.regex("/admin/.*"))
.build()
.globalOperationParameters(pars);
return adminApi;
} private ApiInfo adminApiInfo(){ return new ApiInfoBuilder()
.title("后台管理系统-API文档")
.description("本文档描述了后台管理系统微服务接口定义")
.version("1.0")
.contact(new Contact("cj", "http://cj.com", "cj@qq.com"))
.build();
}
}

3.加注解

package com.cj.system.controller;

import com.atguigu.model.system.SysRole;
import com.cj.system.mapper.SysRoleMapper;
import com.cj.system.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import java.util.List; @Api(tags = "角色管理")
@RestController
@RequestMapping("admin/system/sysRole")
public class SysRoleController {
@Autowired
private SysRoleService sysRoleService; @ApiOperation(value = "获取全部角色列表")
@GetMapping("findAll")
public List<SysRole> findAll(){
List<SysRole> list = sysRoleService.list();
return list; }
@DeleteMapping("remove/{id}")
public boolean remove(@PathVariable("id") Long id){
boolean b = sysRoleService.removeById(id);
return b;
}
}

4.访问

localhost:8800/doc.html

knife4j 整合springboot的更多相关文章

  1. 整合springboot(app后台框架搭建四)

    springboot可以说是为了适用SOA服务出现,一方面,极大的简便了配置,加速了开发速度:第二方面,也是一个嵌入式的web服务,通过jar包运行就是一个web服务: 还有提供了很多metric,i ...

  2. 整合 springboot 和 swagger出问题

    整合 springboot 和 swagger ,出现报错, org.springframework.beans.factory.UnsatisfiedDependencyException: Err ...

  3. 【SpringBoot】搜索框架ElasticSearch介绍和整合SpringBoot

    ========================12章 搜索框架ElasticSearch介绍和整合SpringBoot ============================= 加入小D课堂技术交 ...

  4. netty-socketio整合springboot消息推送

    netty-socketio整合springboot消息推送 1.netty-socketio消息推送 1)在项目中常常涉及到消息推送的情况,消息推送要求的实时性,使用传统的方式已经不能满足需求了: ...

  5. 教你 Shiro 整合 SpringBoot,避开各种坑

    教你 Shiro 整合 SpringBoot,避开各种坑-----https://www.cnblogs.com/HowieYuan/p/9259638.html

  6. 基于 SpringBoot2.0+优雅整合 SpringBoot+Mybatis

    SpringBoot 整合 Mybatis 有两种常用的方式,一种就是我们常见的 xml 的方式 ,还有一种是全注解的方式.我觉得这两者没有谁比谁好,在 SQL 语句不太长的情况下,我觉得全注解的方式 ...

  7. 消息中间件——RabbitMQ(十)RabbitMQ整合SpringBoot实战!(全)

    前言 1. SpringBoot整合配置详解 publisher-confirms,实现一个监听器用于监听Broker端给我们返回的确认请求:RabbitTemplate.ConfirmCallbac ...

  8. Activiti7整合SpringBoot(十二)

    1 SpringBoot 整合 Activiti7 的配置 为了能够实现 SpringBoot 与 Activiti7 整合开发,首先我们要引入相关的依赖支持.所以,我们在工程的 pom.xml 文件 ...

  9. dubbo入门学习(三)-----dubbo整合springboot

    springboot节省了大量的精力去配置各种bean,因此通过一个简单的demo来整合springboot与dubbo 一.创建boot-user-service-provider 本篇博文基于上篇 ...

  10. liberty | 在IDEA整合Springboot与IBM liberty

    在IDEA整合Springboot与IBM liberty 简介 Liberty 是一款全新的轻量级应用服务器,它将用户的良好开发体验作为最主要的出发点.其主要特点和内容包括: 高模块化--该功能允许 ...

随机推荐

  1. [版本控制-Git]-git学习总结

    1.如何将本地的文件添加到已经建好的远程分支上: 1.1 本地文件夹内,右键-git bash - 创建新仓 git init 1.2 git remote add origin 远程仓库的githu ...

  2. docker自动化启动停止脚本

    docker一键启动命令 sh auto.sh [start|restart|stop] [keywords...] keywords可选(包含编号,镜像名,容器名称,端口) 其中defaultLis ...

  3. macOS 系统安装提示应用程序副本已损坏的解决方法

    错误预览: 操作方法,关闭Wi-Fi,网线(以修改时间为 2020 为例): 再次尝试安装吧...

  4. 蓝牙mesh组网实战(智能家居应用)

    目录 蓝牙mesh组网目前存在有入门门槛高的问题,比如,嵌入式工程师需要考虑到标准mesh模型的兼容,app开发工程师需要了解mesh协议栈才能直接走mesh与芯片通信.而沁恒官方提供的透传模型简洁易 ...

  5. jekins+gitlab

    1.jekins安装可以看jekins+shell随笔. 2.安装gitlab rpm    -ivh   gitlab-ce-11.2.0-ce.0.el7.x86_64.rpm 3.修改配置 vi ...

  6. Linux安装jdk之openjdk

    使用yum源 1.查看yum库中都有哪些jdk版本 yum search java|grep jdk 2.选择指定的版本安装,注意最后的 * 以及yum源安装的是openjdk,注意openjdk的区 ...

  7. python web自动化-文件上传-亲身实践

    文件上传三种方式: (一)查看元素标签,如果是input,则可以参照文本框输入的形式进行文件上传 方法:和用户输入是一样的,使用send_keys 步骤:1.找到定位元素,2,输入文件路径 ele=d ...

  8. 浅写java环境配置

    我对于Java环境配置的理解: 下载JDK ==>安装JDK ==>在电脑的系统中添加JDK中所包含的Java环境 ==>重启(主要是给系统监测到环境,非必要,但是建议)==> ...

  9. SpringMVC学习day03

    第1个springmvc程序 这是根据狂神说视频和资料学习的,用于加强自己的记忆 入门学习 1. 步骤: 1.新建一个Moudle , springmvc-02-hello , 添加web的支持! 2 ...

  10. D - Pair of Topics

    D - Pair of Topics 思路: 这个题需要一点思路,ai+aj>bi+bj可以转换成ai-bi+aj-bj>0,也就是c[i]=a[i]-b[i],只需要找c[i]+c[j] ...