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

青岛英文网站建设电商网站制作设计

青岛英文网站建设,电商网站制作设计,订餐网站开发,博野网站建设7. Swagger 7.1 简介 便于前后端集成联调RestFul Api 文档在线生成工具 Api 文档与 Api 定义同步更新直接运行#xff0c;在线测试 Api 接口 7.2 springboot 集成 swagger (1) 导入依赖 !-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger…7. Swagger 7.1 简介 便于前后端集成联调RestFul Api 文档在线生成工具 Api 文档与 Api 定义同步更新直接运行在线测试 Api 接口 7.2 springboot 集成 swagger (1) 导入依赖 !-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -- dependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger2/artifactIdversion2.9.2/version /dependency !-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -- dependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger-ui/artifactIdversion2.9.2/version /dependency(2) 集成 swagger Configuration EnableSwagger2 // 开启 swagger2 public class SwaggerConfig { }(3) swagger 页面信息 接口localhost://8080/swagger-ui.html (4) 配置 swagger 信息 Configuration EnableSwagger2 // 开启 swagger2 public class SwaggerConfig {// 配置 Swagger Docket 的 bean 实例Beanpublic Docket docket() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());}// 配置 swagger api 信息private ApiInfo apiInfo() {// 作者信息Contact contact new Contact(why, https://gitee.com/, 1942953841qq.com);return new ApiInfo(Why Swagger Api Info,Why so serious!!!,v1.0,https://gitee.com/,contact,Apache 2.0,http://www.apache.org/licenses/LICENSE-2.0,new ArrayList());} }(5) 配置 swagger 自定义扫描接口 // 多环境配置注解方法 PropertySource(value classpath:application.properties) Configuration EnableSwagger2 // 开启 swagger2 public class SwaggerConfig {// 配置 Swagger Docket 的 bean 实例Beanpublic Docket docket(Environment environment) {// 多环境配置java 方法// 设置要显示的 swagger 环境// Profiles profiles Profiles.of(dev, test);// 判断是否处在自己设定的环境中// boolean flag environment.acceptsProfiles(profiles);return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())// enable 是否启用 swagger// .enable(flag).select()// RequestHandlerSelectors 配置扫描接口的方式// basePackage 指定要扫描的包// any() 扫描全部// none() 不扫描// withClassAnnotation 扫描类上的注解参数是一个类上的反射对象// withMethodAnnotation 扫描方法上的注解.apis(RequestHandlerSelectors.basePackage(com.why.swagger.controller))// paths 路径过滤// .paths(PathSelectors.ant(/why/**)).build();} }(6) 多文档分组配置 Bean public Docket docket1() {return new Docket(DocumentationType.SWAGGER_2).groupName(A); }Bean public Docket docket2() {return new Docket(DocumentationType.SWAGGER_2).groupName(B); }Bean public Docket docket3() {return new Docket(DocumentationType.SWAGGER_2).groupName(C); }(7) 注解的使用 实体类 /*** ApiModel 用在类上表示对类进行说明用于实体类中的参数接收说明。*/ ApiModel(value com.why.pojo.User, description 用户类) Data AllArgsConstructor NoArgsConstructor public class User {/*** ApiModelProperty() 用于字段表示对 model 属性的说明。*/ApiModelProperty(用户名)private String username;ApiModelProperty(密码)private String password; }接口 /*** Api 用在类上说明该类的作用。* tags接口说明可以在页面中显示。*/ Api(tags Hello 控制器类) RestController public class HelloController {ApiOperation(hello 方法)GetMapping(/hello)public String hello() {return hello;}/*** ApiOperation 用在 Controller 里的方法上说明方法的作用每一个接口的定义。* value接口名称* notes详细说明*/ApiOperation(value user 控制器, notes 获取用户)/*** ApiImplicitParams / ApiImplicitParam 为单独的请求参数进行说明* name参数名对应方法中单独的参数名称。* value参数中文说明。* required是否必填。* paramType参数类型取值为 path、query、body、header、form。* dataType参数数据类型。* defaultValue默认值。*/ApiImplicitParams({ApiImplicitParam(name username, value 用户名, dataType string, paramType query, required true, defaultValue why),ApiImplicitParam(name password, value 密码, dataType string, paramType query, required true, defaultValue 123)})/*** ApiResponse 用于方法上说明接口响应的一些信息ApiResponses 组装了多个 ApiResponse。*/ApiResponses({ ApiResponse(code 200, message OK, response User.class) })PostMapping(value /userObj)/*** ApiParam 用于 Controller 中方法的参数说明。* value参数说明* required是否必填*/public User userObj(ApiParam(value 用户名, required true) String username,ApiParam(value 密码, required true) String password) {User user new User(username, password);System.out.println(user);return user;}}(8) 接口测试 swagger2 测试 get 接口不能传递参数测试 post 接口可以传递参数 即含参接口使用 PostMapping 和 RequestMapping swagger2 测试含参 GetMapping 会报如下错误 TypeError: Failed to execute ‘fetch‘ on ‘Window‘: Request with GET/HEAD method cannot have body. 效果 Get 方法 Post (9) 安全考虑 正式发布一定要关闭 swagger
http://www.sadfv.cn/news/13301/

相关文章:

  • 最新开的手游传奇网站小程序注册平台
  • 78建筑网站做网站公司哪家便宜
  • flash网站管理系统百度关键词排名技术
  • 天津制作网站公司推荐共享网站哪里建
  • 地方志网站建设wordpress 圆角主题
  • 深圳网站建设定制开发 .超凡科技北京seo优化技术
  • 程序网站开发宣城市市政建设集团公司网站
  • 网站建设维护培训班如何创建自己的网站平台免费
  • 网站开发时间表网站制作方案大全
  • dw做的网站如何发布wordpress删除文章
  • 网站空间支持功能快速提升网站排名
  • 公司网站建设费怎么做账惠州免费建站模板
  • asp网站有哪些怎么查公司网站可信度
  • 如何写网站优化方案做网站备案是个人还是企业好
  • 好看英文网站专业的网站建设公司排名
  • 新网互联的网站wordpress增加分类目录
  • 装修网站建设案例苏州百度快照优化排名
  • 大圣网站建设做网站的费用计入什么费用
  • 江西 网站 建设 开发大连云购物app下载安装到手机
  • 西安优化网站自己建设网站要花多少钱
  • 有做lol直播网站家具东莞网站建设
  • 网页设计网站免登陆网站优化公司哪家效果好
  • 做网站累吗网站建设知识库
  • 凡科网可以免费做网站吗crm系统是什么意思
  • 百度一般多久收录网站网页打不开但是有网什么原因如何解决
  • 高性能网站建设 下载公司门户网站建设方案
  • 官方网站拼多多wordpress寄出邮箱地址
  • 聊城高端网站制作南宁自助建站模板下载
  • nas可以做网站服务器吗大商创源码
  • 网站推广计划方案网站建设与管理需要什么软件有哪些方面