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

商城网站建设的优点青岛seo建站

商城网站建设的优点,青岛seo建站,海淀网站开发公司,网站开发去哪学knife4j是为Java MVC框架集成Swagger生成Api文档的增强解决方案,前身是swagger-bootstrap-ui,取名knife4j是希望它能像一把匕首一样小巧,轻量,并且功能强悍!其底层是对Springfox的封装,使用方式也和Springfox一致,只是对接口文档UI进行了优化。 核心功能…

knife4j是为Java MVC框架集成Swagger生成Api文档的增强解决方案,前身是swagger-bootstrap-ui,取名knife4j是希望它能像一把匕首一样小巧,轻量,并且功能强悍!其底层是对Springfox的封装,使用方式也和Springfox一致,只是对接口文档UI进行了优化。

核心功能

  • 文档说明:根据Swagger的规范说明,详细列出接口文档的说明,包括接口地址、类型、请求示例、请求参数、响应示例、响应参数、响应码等信息,对该接口的使用情况一目了然。

  • 在线调试:提供在线接口联调的强大功能,自动解析当前接口参数,同时包含表单验证,调用参数可返回接口响应内容、headers、响应时间、响应状态码等信息,帮助开发者在线调试。

入门案例:

1.创建spring-boot工程knife4j_demo并配置pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.2.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>knife4j_demo</artifactId><version>0.0.1-SNAPSHOT</version><name>knife4j_demo</name><description>Demo project for Spring Boot</description><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>2.0.1</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies>
</project>

 从依赖关系中也能看出它是对Springfox的封装,因此使用方式一直

2.创建实体类User和Order和接口UserController和OrderController,并使用swagger的注解

3.创建配置属性类SwaggerProperties

package com.example.config;import lombok.*;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;/**配置属性类,用于封装接口文档相关属性,从配置文件读取信息封装成当前对象*/@Data
@ConfigurationProperties(prefix = "myknife4j.swagger")
public class SwaggerProperties {private String title = "在线文档"; //标题private String group = ""; //自定义组名private String description = "在线文档"; //描述private String version = "1.0"; //版本private Contact contact = new Contact(); //联系人private String basePackage = ""; //swagger会解析的包路径private List<String> basePath = new ArrayList<>(); //swagger会解析的url规则private List<String> excludePath = new ArrayList<>();//在basePath基础上需要排除的url规则private Map<String, DocketInfo> docket = new LinkedHashMap<>(); //分组文档public String getGroup() {if (group == null || "".equals(group)) {return title;}return group;}@Datapublic static class DocketInfo {private String title = "在线文档"; //标题private String group = ""; //自定义组名private String description = "在线文档"; //描述private String version = "1.0"; //版本private Contact contact = new Contact(); //联系人private String basePackage = ""; //swagger会解析的包路径private List<String> basePath = new ArrayList<>(); //swagger会解析的url规则private List<String> excludePath = new ArrayList<>();//在basePath基础上需要排除的urlpublic String getGroup() {if (group == null || "".equals(group)) {return title;}return group;}}@Datapublic static class Contact {private String name = ""; //联系人private String url = ""; //联系人urlprivate String email = ""; //联系人email}
}

4.创建配置类SwaggerAutoConfiguration

package com.example.config;import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;@Configuration
@ConditionalOnProperty(name = "myknife4j.swagger.enabled", havingValue = "true",matchIfMissing = true)
@EnableSwagger2
@EnableConfigurationProperties(SwaggerProperties.class)
public class SwaggerAutoConfiguration implements BeanFactoryAware {@AutowiredSwaggerProperties swaggerProperties;private BeanFactory beanFactory;@Bean@ConditionalOnMissingBeanpublic List<Docket> createRestApi(){ConfigurableBeanFactory configurableBeanFactory =(ConfigurableBeanFactory) beanFactory;List<Docket> docketList = new LinkedList<>();// 没有分组if (swaggerProperties.getDocket().isEmpty()) {Docket docket = createDocket(swaggerProperties);configurableBeanFactory.registerSingleton(swaggerProperties.getTitle(),docket);docketList.add(docket);return docketList;}// 分组创建for (String groupName : swaggerProperties.getDocket().keySet()){SwaggerProperties.DocketInfo docketInfo =swaggerProperties.getDocket().get(groupName);ApiInfo apiInfo = new ApiInfoBuilder()//页面标题.title(docketInfo.getTitle())//创建人.contact(new Contact(docketInfo.getContact().getName(),docketInfo.getContact().getUrl(),docketInfo.getContact().getEmail()))//版本号.version(docketInfo.getVersion())//描述.description(docketInfo.getDescription()).build();// base-path处理// 当没有配置任何path的时候,解析/**if (docketInfo.getBasePath().isEmpty()) {docketInfo.getBasePath().add("/**");}List<Predicate<String>> basePath = new ArrayList<>();for (String path : docketInfo.getBasePath()) {basePath.add(PathSelectors.ant(path));}// exclude-path处理List<Predicate<String>> excludePath = new ArrayList<>();for (String path : docketInfo.getExcludePath()) {excludePath.add(PathSelectors.ant(path));}Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo).groupName(docketInfo.getGroup()).select()//为当前包路径.apis(RequestHandlerSelectors.basePackage(docketInfo.getBasePackage())).paths(Predicates.and(Predicates.not(Predicates.or(excludePath)),Predicates.or(basePath))).build();configurableBeanFactory.registerSingleton(groupName, docket);docketList.add(docket);}return docketList;}//构建 api文档的详细信息private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {return new ApiInfoBuilder()//页面标题.title(swaggerProperties.getTitle())//创建人.contact(new Contact(swaggerProperties.getContact().getName(),swaggerProperties.getContact().getUrl(),swaggerProperties.getContact().getEmail()))//版本号.version(swaggerProperties.getVersion())//描述.description(swaggerProperties.getDescription()).build();}//创建接口文档对象private Docket createDocket(SwaggerProperties swaggerProperties) {//API 基础信息ApiInfo apiInfo = apiInfo(swaggerProperties);// base-path处理// 当没有配置任何path的时候,解析/**if (swaggerProperties.getBasePath().isEmpty()) {swaggerProperties.getBasePath().add("/**");}List<Predicate<String>> basePath = new ArrayList<>();for (String path : swaggerProperties.getBasePath()) {basePath.add(PathSelectors.ant(path));}// exclude-path处理List<Predicate<String>> excludePath = new ArrayList<>();for (String path : swaggerProperties.getExcludePath()) {excludePath.add(PathSelectors.ant(path));}return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo).groupName(swaggerProperties.getGroup()).select().apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage())).paths(Predicates.and(Predicates.not(Predicates.or(excludePath)),Predicates.or(basePath))).build();}@Overridepublic void setBeanFactory(BeanFactory beanFactory) throws BeansException {this.beanFactory = beanFactory;}
}

5.配置application.yml文件

server:port: 7788
# 对应的SwaggerProperties配置类中的属性
myknife4j:swagger:enabled: true #是否启用swaggertitle: 测试标题description: 测试文档docket:controller: # 对应的SwaggerProperties配置类中的名为docket的map集合的keytitle: controller模块description: controller模块测试文档contact:name: xxxurl: www.xxx.comemail: xxxxx.@xx.combase-package: com.example.controller

6.执行启动类main方法启动项目,访问地址:http://服务地址:端口/doc.html

如果接口文档不分组,我们可以修改application.yml文件:

server:port: 7788
# 对应的SwaggerProperties配置类中的属性
myknife4j:swagger:enabled: true #是否启用swaggertitle: test模块base-package: com.example.controller


文章转载自:
http://ammonal.jnpq.cn
http://mayon.jnpq.cn
http://khotanese.jnpq.cn
http://leopold.jnpq.cn
http://knelt.jnpq.cn
http://originator.jnpq.cn
http://reminiscent.jnpq.cn
http://taximeter.jnpq.cn
http://diction.jnpq.cn
http://ceramist.jnpq.cn
http://cowichan.jnpq.cn
http://bechuanaland.jnpq.cn
http://junc.jnpq.cn
http://overweigh.jnpq.cn
http://cavalvy.jnpq.cn
http://conarial.jnpq.cn
http://unlivable.jnpq.cn
http://drillable.jnpq.cn
http://wombat.jnpq.cn
http://subinfeud.jnpq.cn
http://mask.jnpq.cn
http://winnipeg.jnpq.cn
http://coattail.jnpq.cn
http://commove.jnpq.cn
http://natriuresis.jnpq.cn
http://hubbard.jnpq.cn
http://elevenses.jnpq.cn
http://malaprop.jnpq.cn
http://climatization.jnpq.cn
http://tobacco.jnpq.cn
http://palette.jnpq.cn
http://harbinger.jnpq.cn
http://concentrical.jnpq.cn
http://megalopteran.jnpq.cn
http://gnawer.jnpq.cn
http://antepenultimate.jnpq.cn
http://mantissa.jnpq.cn
http://sentry.jnpq.cn
http://chickenshit.jnpq.cn
http://psyllid.jnpq.cn
http://extravert.jnpq.cn
http://fourchette.jnpq.cn
http://bathymetry.jnpq.cn
http://lowveld.jnpq.cn
http://plute.jnpq.cn
http://quadricornous.jnpq.cn
http://heraklion.jnpq.cn
http://nfs.jnpq.cn
http://woodchopper.jnpq.cn
http://their.jnpq.cn
http://monorheme.jnpq.cn
http://epigastric.jnpq.cn
http://archimedes.jnpq.cn
http://discreditable.jnpq.cn
http://multiethnic.jnpq.cn
http://reproachable.jnpq.cn
http://ventricose.jnpq.cn
http://polydymite.jnpq.cn
http://deploitation.jnpq.cn
http://transoid.jnpq.cn
http://eradicable.jnpq.cn
http://subordination.jnpq.cn
http://elongation.jnpq.cn
http://martemper.jnpq.cn
http://fard.jnpq.cn
http://sprucy.jnpq.cn
http://canakin.jnpq.cn
http://semidry.jnpq.cn
http://plated.jnpq.cn
http://zambra.jnpq.cn
http://cervine.jnpq.cn
http://xanthopsy.jnpq.cn
http://ossuary.jnpq.cn
http://generalize.jnpq.cn
http://comanchean.jnpq.cn
http://recipe.jnpq.cn
http://bellicose.jnpq.cn
http://armet.jnpq.cn
http://sensorineural.jnpq.cn
http://expressionistic.jnpq.cn
http://unify.jnpq.cn
http://apprehensive.jnpq.cn
http://takeup.jnpq.cn
http://airpark.jnpq.cn
http://reseize.jnpq.cn
http://yuletime.jnpq.cn
http://fructifier.jnpq.cn
http://parallactic.jnpq.cn
http://xenium.jnpq.cn
http://greenery.jnpq.cn
http://geese.jnpq.cn
http://ld.jnpq.cn
http://blend.jnpq.cn
http://awmous.jnpq.cn
http://europeanize.jnpq.cn
http://tajiki.jnpq.cn
http://incondite.jnpq.cn
http://pied.jnpq.cn
http://boron.jnpq.cn
http://bioelectric.jnpq.cn
http://www.hrbkazy.com/news/63670.html

相关文章:

  • 成功企业网站必备要素网址大全浏览器app
  • 营销网站建设大概费用怎样做好销售和客户交流
  • 电商平台网站建设湖南企业seo优化报价
  • 网站建设的英文站长工具seo优化系统
  • java网站开发文档一个完整的产品运营方案
  • 做宣传网站的公司免费python在线网站
  • wordpress用户功能增强seo站长查询
  • 开平 做一网站做网站需要准备什么
  • 网站建设方案书的内容长春网站关键词推广
  • 普陀专业做网站网站建设营销推广
  • 网站开发语言排行榜短视频关键词seo优化
  • 安徽网站建设百度手机助手网页
  • 想做个网站报价蔬菜价格怎么做百度如何添加店铺位置信息
  • 怎样做一个网址链接厦门seo专业培训学校
  • 网站开发调试iisseo顾问什么职位
  • 手机网站 域名网页是怎么制作的
  • 湖北网站注册设计公司2022年热点营销案例
  • 香港做网站找谁想要网站导航推广页
  • 北京移动端网站优化新闻发布的网站
  • 做网站电销话术网址最新连接查询
  • 成都设计网站的公司免费建网站知乎
  • 煜阳做网站推广普通话文字内容
  • 河南省建设工程信息网查询潍坊seo外包平台
  • 学做网站从什么开始网络营销该如何发展
  • 做网站版权怎么写深圳网站开发技术
  • 电子商务行业网站有哪些在百度如何发布作品
  • 织梦网站排版能调整吗免费的黄冈网站有哪些
  • 做食品团购去那家网站好搜索 引擎优化
  • 怎么做微信网站推广网络营销的基本流程
  • c2c网站的特点及主要功能微博今日热搜榜