这篇文章给大家分享的是有关java大摇大摆ui如何添加标题请求头参数的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
我用到的时髦的主要有三款产品,大摇大摆编辑,大摇大摆的ui和大摇大摆codegen .
<强>大摇大摆主编:强>主要是一个本地客户端,用来自己添加api,自己来测试,相当于一个api的可视化测试工具和定义工具吧。
<强>大摇大摆ui: 强>主要用户嵌入到项目中,将所有的接口生成一个可视化的页面,方便前后端联调
<强>大摇大摆codegen: 强>主要用于通过大摇大摆来自动生成代码
我用的轻便ui主要在java项目中。将所有的http接口提供一个可视化页面。供前端同学看的到,联调非常方便,所有的接口一目了然。
但是在使用大摇大摆ui的时候,我有一个新的需求,就是我所有的接口都必须授权才能访问,即每个接口都必须添加一个标题里的参数。一般用授权,但是我的键是票。于是尝试配置大摇大摆,将每个接口都默认增加一个票的请求参数。
我在java中用的轻便框架是springfox.springfox是比较新的,官方也一直在更新. java添加吓唬我就不详细介绍了,这里只介绍如何在所有的大摇大摆接口中默认都添加头参数
<强>粘贴springfox配置如下:强> <强>
强>
package cn.ce.platform_service.interceptors; , import java.util.ArrayList; import 并不知道; , import org.springframework.context.annotation.Bean; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; , import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.schema.ModelRef; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Parameter; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; ,/* * 时间:*,@Description 大摇大摆配置配置 *,@Author :火星 时间:*,@Date 2017年9月6日 */@WebAppConfiguration @EnableSwagger2 @EnableWebMvc//@ComponentScan (basePackageClasses =, {ApisController.class }),//Instructs spring where 用scan for API 控制器 public class  SwaggerConfig { ,/* * ,,*,Every Docket bean is picked up by 从而swagger-mvc framework 作用;allowing for 多个 ,,*,swagger groups 即只same code base multiple swagger resource 清单。 ,,*/,@ bean public 才能;Docket  customDocket () { ,,ParameterBuilder ticketPar =, new ParameterBuilder (); ,,,List, pars =, new ArrayList ();, ,,ticketPar.name (“ticket") .description (“user ticket") ,,.modelRef (new ModelRef (“string")) .parameterType (“header"), ,,.required (false) .build();,//头中的票参数非必填,传空也可以 ,,pars.add (ticketPar.build());,,//根据每个方法名也知道当前方法在设置什么参数 , ,,,return new 摘要(DocumentationType.SWAGGER_2) ,,,,.select () ,,,,.apis (RequestHandlerSelectors.any ()), ,,,,,,,.build (), ,,,,,,,.globalOperationParameters (pars), ,,,,,,,.apiInfo (apiInfo ()); ,,} ,, ApiInfo 才能;apiInfo (), {, ,,return new  ApiInfoBuilder (), ,,,,,.title (“api swagger document"), ,,,,,.description(“前后端联调swagger api 文档“), ,,,,,.version (“2.1.5.5"), ,,,,,.build (); ,,}, }
修改大摇大摆的配置文件如上即能满足大摇大摆中所有的接口默认都加上票参数,非必填如下图:
java是什么
java是一门面向对象编程语言,可以编写桌面应用程序,网络应用程序,分布式系统和嵌入式系统应用程序。
感谢各位的阅读!关于“java ui大摇大摆如何添加标题请求头参数”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!