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

wordpress 打车长沙网站搭建优化

wordpress 打车,长沙网站搭建优化,项目外包公司可以去吗,微信网站公司swagger集成文档具有功能丰富、及时更新、整合简单&#xff0c;内嵌于应用的特点。 由于后台管理和前台接口均需要接口文档&#xff0c;所以在工具包构建BaseSwaggerConfig基类。 1.引入依赖 <dependency><groupId>io.springfox</groupId><artifactId>…

swagger集成文档具有功能丰富、及时更新、整合简单,内嵌于应用的特点。

由于后台管理和前台接口均需要接口文档,所以在工具包构建BaseSwaggerConfig基类。
1.引入依赖

 <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version></dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version></dependency>

2.需要添加Swagger配置类。

/*** Swagger基础配置*/
public abstract class BaseSwaggerConfig {@Beanpublic Docket createRestApi() {SwaggerProperties swaggerProperties = swaggerProperties();Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo(swaggerProperties)).select().apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage())).paths(PathSelectors.any()).build();if (swaggerProperties.isEnableSecurity()) {docket.securitySchemes(securitySchemes()).securityContexts(securityContexts());}return docket;}private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {return new ApiInfoBuilder().title(swaggerProperties.getTitle()).description(swaggerProperties.getDescription()).contact(new Contact(swaggerProperties.getContactName(), swaggerProperties.getContactUrl(), swaggerProperties.getContactEmail())).version(swaggerProperties.getVersion()).build();}private List<ApiKey> securitySchemes() {//设置请求头信息List<ApiKey> result = new ArrayList<>();ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header");result.add(apiKey);return result;}private List<SecurityContext> securityContexts() {//设置需要登录认证的路径List<SecurityContext> result = new ArrayList<>();result.add(getContextByPath("/*/.*"));return result;}private SecurityContext getContextByPath(String pathRegex) {return SecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.regex(pathRegex)).build();}private List<SecurityReference> defaultAuth() {List<SecurityReference> result = new ArrayList<>();AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];authorizationScopes[0] = authorizationScope;result.add(new SecurityReference("Authorization", authorizationScopes));return result;}/*** 自定义Swagger配置*/public abstract SwaggerProperties swaggerProperties();
}
  1. 将需要配置的字段提取出来,单独作为一类
/*** Swagger自定义配置*/
@Data
@EqualsAndHashCode(callSuper = false)
@Builder
public class SwaggerProperties {/*** API文档生成基础路径*/private String apiBasePackage;/*** 是否要启用登录认证*/private boolean enableSecurity;/*** 文档标题*/private String title;/*** 文档描述*/private String description;/*** 文档版本*/private String version;/*** 文档联系人姓名*/private String contactName;/*** 文档联系人网址*/private String contactUrl;/*** 文档联系人邮箱*/private String contactEmail;
}
  1. 前台接口和后台管理的包的配置,只需要继承重写该类就行了
/*** Swagger API文档相关配置*/
@Configuration
@EnableSwagger2
public class SwaggerConfig extends BaseSwaggerConfig {@Overridepublic SwaggerProperties swaggerProperties() {return SwaggerProperties.builder().apiBasePackage("com.example.admin").title("后台管理系统").description("后台相关接口文档").contactName("author").version("1.0").enableSecurity(true).build();}
}

接着就可以访问http://localhost:8001/swagger-ui/index.html接口文档页面了,后续可以通过swagger来测试接口。
详细配置参考:https://swagger.io/

http://www.hkea.cn/news/386661/

相关文章:

  • 深圳网站建设科技有限公司注册一个网站
  • 网站设计改版seo关键词优化推广价格
  • 做网站什么主题比较好上海网站seo诊断
  • 设计苹果手机的网站病毒什么时候才能消失
  • 国外做化工产品的网站自媒体发布平台
  • 怎么做资源类网站百度搜索热度排名
  • 大片网站建设seo关键词排名优化评价
  • 网络营销推广课程培训苏州seo门户网
  • 做盗版影视网站如何给公司网站做推广
  • 做网站付费流程郑州seo技术
  • 云南网站开发有哪些实用的网络推广方法
  • 央视新闻最新消息今天什么叫seo
  • 网站建设的意义徐州百度推广
  • 建设网站建设的目标百度云盘资源
  • 个体工商户是否能够做网站在线生成个人网站源码
  • 临沂高端网站建设厦门网站推广费用
  • 网站模版友链交易交易平台
  • 武汉做网站找谁百度导航是哪个国家的
  • wordpress互动游戏黄石seo诊断
  • 网页设计作品下载志鸿优化设计
  • 宾馆网站制作seminar是什么意思
  • 网站建设的进度表爱站查询工具
  • 深圳聘请做网站人员长春刚刚最新消息今天
  • 汽配人网做网站沈阳网站seo公司
  • 网站 短链接怎么做网站建设网站定制
  • 网站开发凭证做什么科目百度推广关键词多少合适
  • 网站正在建设 h5模板新闻热点
  • 龙岗公司网站建设怎么上百度搜索
  • 七米网站建设网站自动推广软件免费
  • 余姚公司做网站跨境电商怎么做