使用Knife4j美化Swagger

2021-10-24 19:00:56 字數 3398 閱讀 8990

使用knife4j美化swagger

>

>

>

org.springframework.bootgroupid

>

>

spring-boot-starter-webartifactid

>

dependency

>

>

>

io.springfoxgroupid

>

>

springfox-swagger-uiartifactid

>

>

2.7.0version

>

dependency

>

>

>

io.springfoxgroupid

>

>

springfox-swagger2artifactid

>

>

2.7.0version

>

dependency

>

>

>

com.github.xiaoymingroupid

>

>

knife4j-spring-boot-starterartifactid

>

>

2.0.4version

>

dependency

>

>

>

org.projectlombokgroupid

>

>

lombokartifactid

>

>

trueoptional

>

dependency

>

>

>

org.springframework.bootgroupid

>

>

spring-boot-starter-testartifactid

>

>

testscope

>

>

>

>

org.junit.vintagegroupid

>

>

junit-vintage-engineartifactid

>

exclusion

>

exclusions

>

dependency

>

dependencies

>

package com.blu.config;

import org.springframework.context.annotation.bean;

import org.springframework.context.annotation.configuration;

import springfox.documentation.builders.apiinfobuilder;

import springfox.documentation.builders.pathselectors;

import springfox.documentation.builders.requesthandlerselectors;

import springfox.documentation.service.apiinfo;

import springfox.documentation.spi.documentationtype;

import springfox.documentation.spring.web.plugins.docket;

import springfox.documentation.swagger2.annotations.enableswagger2;

@configuration

@enableswagger2

public

class

swaggerconfiguration

private apiinfo apiinfo()

}

package com.blu.entity;

import io.swagger.annotations.apimodelproperty;

import lombok.data;

@data

public

class

user

package com.blu.controller;

import org.springframework.web.bind.annotation.requestparam;

import org.springframework.web.bind.annotation.restcontroller;

import com.blu.entity.user;

import io.swagger.annotations.api;

import io.swagger.annotations.apioperation;

import io.swagger.annotations.apiparam;

@api

(value=

"hellocontroller"

,tags=

"hellocontroller控制類"

)@restcontroller

public

class

hellocontroller

@apioperation

("hellocontroller控制類中的user()方法")(

"/user"

)public user user()

@apioperation

("hellocontroller控制類中的hello2()方法")(

"/hello2"

)public string hello2

(@apiparam

("hello2()方法中的username引數"

)@requestparam string username)

}

啟動後,訪問:http://localhost:8080/swagger-ui.html

訪問:http://localhost:8080/doc.html

swagger增強框架Knife4j

swagger增強knife4j 我稱之為swagger plus 哈哈哈,使用起來特別簡單,在有swagger的基礎上,com.github.xiaoymin groupid knife4j spring boot starter artifactid 2.0.4 version dependen...

介面自動生成工具 knife4j

com.github.xiaoymingroupid knife4j spring boot starterartifactid dependency 2 在模組中新增乙個關於knife4j的配置類 package com.cast.common.knife4j import com.github....

Knife4j新增lombok及註解初探

在pom檔案裡新增包 1 2 dependency 3 groupid org.projectlombok groupid 4 artifactid lombok artifactid 5 optional true optional 6dependency view code 使用例項 註解載入類...