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. 06 RDD编程

    总共有多少学生?map(), distinct(), count() 开设了多少门课程? 每个学生选修了多少门课?map(), countByKey() 每门课程有多少个学生选?map(), coun ...

  2. D8-16K加密锁配置流程

    1.vscode安装yttool插件,可在拓展商店中搜索ext:yt即可找到. 补充地址:https://marketplace.visualstudio.com/items?itemName=ytk ...

  3. vite+vue3.0+ts搭建项目

    项目git地址:https://gitee.com/suyong01/vue3-ts-template vue+ts+vite项目初始化 # npm 6.x npm init @vitejs/app ...

  4. 免费语音转文字----使用Adobe Premiere Pro

    软件版本:Adobe Premiere Pro 2023   打开Adobe Premiere Pro,新建项目:   将要转为文字的录音拖入轨道:   序列→自动转录序列:   选择想要的设置,转录 ...

  5. 自定义Ribbon负载均衡

    需要在基包的上一级定义,不然会被扫到如:com.cn.me,要和me同级 然后自定义两个类 DshzsRandomRule类写自己定义的算法,DshzsRule写注入的bean import com. ...

  6. mac 暗黑破坏神2

    ​ https://590m.com/f/28636472-500475496-61a14b (访问密码:7410) 此版本可以更改人员属性参数,过程有点复杂,如需了解,请留言+v沟通吧... ​编辑 ...

  7. Java笔记_this关键字_HomeWork(5 - 9 题)

    第五题 /** * @ClassName HomeWork05 * @Description TODO * @Author Orange * @Date 2021/4/25 10:09 * @Vers ...

  8. PADS生成CAM文档(Gerber)

    CAM   一个正常的CAM文档应包括n+8层,n指的是层数,8指的是: 顶层丝印层,Silkscreen TOP 底层丝印层,Silkscreen BOTTOM 顶层组焊层,Solder Mask ...

  9. 个人css样式

    <style> .div1{ width:200px; height:100px; border:1px solid #dddddd; transition:all 0.5s linear ...

  10. 记:java.lang.IllegalArgumentException: DAY_OF_MONTH 报错

    查询的时候报错: 月份中的天数错误 原因:  date日期列中有数据错误 修改数据库中错误的数据就可以了.