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. Linux - tar 命令详解 (压缩,解压,加密压缩,解密压缩)

    压缩tar -czvf /path/to/file.tar.gz file  (第一个参数:文件压缩的位置和名字  第二个参数:需要压缩的文件) 解压 tar -xzvf /path/to/file. ...

  2. TIM PC版 v3.4.5.22071 绿色便携版

    修改历史: 2023.01.30:自改官方 3.4.5.22071 最新正式版本------------------------------------------------------------ ...

  3. grafana嵌入iframe,websoket连接报错400或403(nginx代理)

    1.custom.ini配置文件修改allowed_origins=* 2. nginx中增加配置,如下:

  4. 前端常见的Vue面试题目汇总

    请说一下响应式数据的原理 默认Vue在初始化数据时,会给data中的属性使用Object.defineProperty重新定义所有属性,当页面到对应属性时,会进行依赖收集(收集当前组件中的watche ...

  5. SpringBoot容器化的多环境配置

    SpringBoot容器化的多环境配置 部署通常会有多个环境,如"dev"/"test"/"prod"等环境 容器化部署通常使用环境变量,而 ...

  6. Section 2.1: Falsy VSTruthy Value and == VS ===

    Falsy VS Truthy Value and == VS === Falsy values: undefined, null, 0, '', NaN Truthy values: Not fal ...

  7. go简单写个ini配置文件读取工具

    直接上代码: 1 package main 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "reflect" 7 ...

  8. 记录一次阿里云ECS搭建代理服务器的过程

    [参考资料](Tinyproxy安装与配置(ip代理) - 林先生 (downdawn.com)) 1.一键安装脚本 vim proxy.sh #! /bin/bash # 配置文件 CONFIG_F ...

  9. react项目--路由封装

    import React, { lazy } from "react"; import Home from "../views/Home"; import Lo ...

  10. element-ui学习之-------input表单验证【各种情况总结】

    1.非必填,正整数 2.非0开头正整数