当前位置: 首页 > news >正文

十大中文网站排名互联网平台公司有哪些

十大中文网站排名,互联网平台公司有哪些,教育类网站设计,南宫建设局网站首页Swagger配置扫描接口 1、构建Docket时通过select()方法配置怎么扫描接口。 Bean public Docket docket() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()// 通过.select()方法#xff0c;去配置扫描接口,RequestHandlerSelectors配置如何扫描…Swagger配置扫描接口 1、构建Docket时通过select()方法配置怎么扫描接口。 Bean public Docket docket() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()// 通过.select()方法去配置扫描接口,RequestHandlerSelectors配置如何扫描接口.apis(RequestHandlerSelectors.basePackage(com.kuang.swagger.controller)).build(); }2、重启项目测试由于我们配置根据包的路径扫描接口所以我们只能看到一个类 3、除了通过包路径配置扫描接口外还可以通过配置其他方式扫描接口这里注释一下所有的配置方式 any() // 扫描所有项目中的所有接口都会被扫描到 none() // 不扫描接口 // 通过方法上的注解扫描如withMethodAnnotation(GetMapping.class)只扫描get请求 withMethodAnnotation(final Class? extends Annotation annotation) // 通过类上的注解扫描如.withClassAnnotation(Controller.class)只扫描有controller注解的类中的接口 withClassAnnotation(final Class? extends Annotation annotation) basePackage(final String basePackage) // 根据包路径扫描接口4、除此之外我们还可以配置接口扫描过滤 Bean public Docket docket() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()// 通过.select()方法去配置扫描接口,RequestHandlerSelectors配置如何扫描接口.apis(RequestHandlerSelectors.basePackage(com.kuang.swagger.controller))// 配置如何通过path过滤,即这里只扫描请求以/kuang开头的接口.paths(PathSelectors.ant(/kuang/**)).build(); }5、这里的可选值还有 any() // 任何请求都扫描 none() // 任何请求都不扫描 regex(final String pathRegex) // 通过正则表达式控制 ant(final String antPattern) // 通过ant()控制配置Swagger开关 1、通过enable()方法配置是否启用swagger如果是falseswagger将不能在浏览器中访问了 Bean public Docket docket() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).enable(false) //配置是否启用Swagger如果是false在浏览器将无法访问.select()// 通过.select()方法去配置扫描接口,RequestHandlerSelectors配置如何扫描接口.apis(RequestHandlerSelectors.basePackage(com.kuang.swagger.controller))// 配置如何通过path过滤,即这里只扫描请求以/kuang开头的接口.paths(PathSelectors.ant(/kuang/**)).build(); }2、如何动态配置当项目处于test、dev环境时显示swagger处于prod时不显示 Bean public Docket docket(Environment environment) {// 设置要显示swagger的环境Profiles of Profiles.of(dev, test);// 判断当前是否处于该环境// 通过 enable() 接收此参数判断是否要显示boolean b environment.acceptsProfiles(of);return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).enable(b) //配置是否启用Swagger如果是false在浏览器将无法访问.select()// 通过.select()方法去配置扫描接口,RequestHandlerSelectors配置如何扫描接口.apis(RequestHandlerSelectors.basePackage(com.kuang.swagger.controller))// 配置如何通过path过滤,即这里只扫描请求以/kuang开头的接口.paths(PathSelectors.ant(/kuang/**)).build(); }3、可以在项目中增加一个dev的配置文件查看效果 总代码 SwaggerConfig package com.xxxx.swagger2.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.core.env.Profiles; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.service.VendorExtension; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2;import java.util.ArrayList;import static springfox.documentation.service.ApiInfo.DEFAULT_CONTACT;Configuration // 开启Swagger2 EnableSwagger2 public class SwaggerConfig {// 配置了Swagger的Docket的bean实例// enable是否启动Swagger,如果为false,则Swagger不能在浏览器中访问Beanpublic Docket docket(Environment environment){// 设置要显示的Swagger环境Profiles profiles Profiles.of(dev,test);// 通过environment.acceptsProfiles判断是否处在自己设定的环境当中boolean flag environment.acceptsProfiles(profiles);return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).enable(flag).select()// RequestHandlerSelectors ,配置要扫描接口的方式// basePackage:指定要扫描的包// any():扫描全部// none():都不扫描// withClassAnnotation:扫描类上的注解,参数是一个注解的反射对象// withMethodAnnotation:扫描方法上的注解.apis(RequestHandlerSelectors.basePackage(com.xxxx.swagger2.controller))// paths():过滤什么路径// .paths(PathSelectors.ant(/xxxx/**)).build();}// 配置Swagger信息 apiInfo()private ApiInfo apiInfo(){Contact contact new Contact(firetang,http://wwww.baidu.com,123132qq.com);return new ApiInfo(firetangApidocument,the author is very cool,1.0,http://www.baidu.com,contact,Apache 2.0,http://www.apache.org/licenses/LICENSE-2.0,new ArrayListVendorExtension());}} application.properties spring.profiles.activedevapplication-dev.properties server.port8081application-pro.properties server.port8082
http://www.yutouwan.com/news/429528/

相关文章:

  • 百度网站关键字广州网址大全
  • 微信小程序怎么做购物网站平台软件
  • 21天网站建设实录php做简单网站 多久
  • 成都市房产信息网查询南山网站seo
  • 天津网站吗做网站公司哪个比较好
  • 网站先做前端还是后端wordpress php 采集器
  • 论坛网站开发成本高端的网站开发
  • 蒙特网站建设加强政协网站建设
  • 正规的国内网站建设公司深圳的seo网站排名优化
  • 工程建设期刊网站网站进度条
  • 怎么看网站关键词密度做app和做网站相同和区别
  • 给个网站谢谢各位了用ps怎么做学校网站页面
  • app网站建设工作师莱芜新闻联播直播
  • 中国建设网官方网站企业登录wordpress中文注册插件
  • 校园网站建设培训体会清徐网站建设
  • 做母婴网站赚钱iis部署网站提示建设中
  • 设计师应该知道的网站网站兼容浏览器
  • 响应式网站好处移动网站怎么登录
  • 网站建设中的风险风险一元云购网站建设模块
  • 天天向上做图网站内蒙网
  • 邢台网站建设03191688深圳高端网站制作
  • 建立公司网站需要多少钱国外创意产品设计作品
  • 网站制作要多长时间怎么自己做彩票网站
  • 网站收录查询方法宠物寄养网站毕业设计
  • 如何利用div做网站个人自助网站
  • 做旅游网站有前途吗做公司网站需要制作内容
  • 做设计的需要网站下载素材吗自己做的网站怎么发布上
  • 网站排名优化各公司的如何在自己的网站上做h5页面
  • 网站要注册为什么企业网站搜索优化
  • 株洲网站搜索优化宝石汇网站