在上乙個文件中,我們已經可以初步使用knife4j了, 但是會發現,如果我是多模組開發,或者寫在不同的controller中的時候,很難配置掃瞄多個包,本本就是為了解決這個問題的.
我們只需要在上乙個文件中新增幾行簡單的**就可以實現配置多個包了
給knife4jconfiguration配置類新增如下的**:
// 定義分隔符,配置swagger多包
private
static
final string splitor =
";";
public
static predicate
basepackage
(final string basepackage)
private
static function?>
, boolean>
handlerpackage
(final string basepackage)
}return
false;}
;}private
static optional<
?extends
class
<
?>>
declaringclass
(requesthandler input)
然年就可以在設定api的地方自定義掃碼的controller了,效果如下:
@bean
(value =
"defaultapi2"
)public docket defaultapi2()
整個的效果如下:
package com.aluphy.config;
import com.google.common.base.function;
import com.google.common.base.optional;
import com.google.common.base.predicate;
import org.springframework.context.annotation.bean;
import org.springframework.context.annotation.configuration;
import springfox.documentation.requesthandler;
import springfox.documentation.builders.apiinfobuilder;
import springfox.documentation.builders.pathselectors;
import springfox.documentation.spi.documentationtype;
import springfox.documentation.spring.web.plugins.docket;
import springfox.documentation.swagger2.annotations.enableswagger2;
@configuration
@enableswagger2
public
class
knife4jconfiguration
public
static predicate
basepackage
(final string basepackage)
private
static function?>
, boolean>
handlerpackage
(final string basepackage)
}return
false;}
;}private
static optional<
?extends
class
<
?>>
declaringclass
(requesthandler input)
}
使用Knife4j美化Swagger
使用knife4j美化swagger org.springframework.bootgroupid spring boot starter webartifactid dependency io.springfoxgroupid springfox swagger uiartifactid 2.7...
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....