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

精湛的中山网站建设新闻发布会

精湛的中山网站建设,新闻发布会,网站建设的功能需求分析,2022年全国文明城市文章目录Swagger3常用配置注解接口测试API信息配置Swagger3 Docket开关,过滤,分组Swagger3常用配置注解 ApiImplicitParams,ApiImplicitParam:Swagger3对参数的描述。 参数名参数值name参数名value参数的具体意义,作用。required参…

文章目录

        • Swagger3常用配置注解
        • 接口测试
        • API信息配置
        • Swagger3 Docket开关,过滤,分组

Swagger3常用配置注解

@ApiImplicitParams,@ApiImplicitParam:Swagger3对参数的描述。

参数名参数值
name参数名
value参数的具体意义,作用。
required参数是否必填。
dataType参数的数据类型。
paramType查询参数类型

paramType有如下几种形式:

类型作用
path以地址的形式提交数据
query直接跟参数完成自动映射赋值
body以流的形式提交,仅支持post
header参数在request headers里边提交
form以form表单的形式提交,仅支持post

@ApiResponses, @ApiResponse:Swagger3对响应信息的描述。

参数名参数值
code响应码:400
message信息,例如:请求参数类型错误。
response抛出异常的类。

Controller层

package com.xct.swagger_1.controller.one;import com.xct.swagger_1.entity.User;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;/*** @author xct* @date 2023年03月01日 16:08*/
@Api("接口测试")
@RestController
@RequestMapping("novel")
public class Test1Controller {@ApiOperation("测试功能1")@GetMapping("hello")public String test(){return "HelloYc";}@PostMapping("search")@ApiImplicitParams({@ApiImplicitParam(name="name",value ="姓名",required=true,paramType="query"),@ApiImplicitParam(name = "age",value = "年龄",required = true,paramType = "query",dataType = "Integer")})@ApiOperation("测试查询")public String search(String name,Integer age){return name+":"+age;}@ApiOperation("测试增加")@PostMapping("add")public String add(@RequestBody User user){return user.getName()+":"+user.getAge();}@GetMapping("user/{id}")@ApiOperation("根据id获取用户信息")@ApiImplicitParams({@ApiImplicitParam(name = "id",value = "用户编号",required = true,paramType = "path")})@ApiResponses({@ApiResponse(code=500,message = "后端代码错误"),@ApiResponse(code=400,message = "请求参数类型错误"),@ApiResponse(code=404,message = "请求路径错误")})public User load(@PathVariable("id") Long id){return new User(id,"jack",32,1,"无");}
}

接口测试


在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

API信息配置

SwaggerConfig配置文件

package com.xct.swagger_1.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;@Configuration
//@EnableSwagger2 //swagger3版本不需要使用这个注解,当然写上也无所谓~
public class SwaggerConfig {//配置Swagger的Docket bean@Beanpublic Docket createRestApi1() {return new Docket(DocumentationType.OAS_30)// 指定Swagger3.0版本.groupName("开发组001").select().apis(RequestHandlerSelectors.basePackage("com.xct.swagger_1.controller.one"))//扫描指定包下的api.build().apiInfo(createApiInfo());}@Beanpublic Docket createRestApi2() {return new Docket(DocumentationType.OAS_30)// 指定Swagger3.0版本.groupName("开发组002").select().apis(RequestHandlerSelectors.basePackage("com.xct.swagger_1.controller.two"))//扫描指定包下的api.build().apiInfo(createApiInfo());}@Beanpublic ApiInfo createApiInfo() {return new ApiInfoBuilder().title("yc&xct管理平台").description("yc&xct管理平台 API接口文档").license("南京信息技术有限公司").licenseUrl("").version("1.0").build();}
}

Swagger3 Docket开关,过滤,分组

开关:调用enable方法。
开:

在这里插入图片描述
关:

在这里插入图片描述
过滤:调用select方法;通过apis方法,basePackage可以根据包路径来生成特定类的API,any方法是默认所有都有效,none方法都无效。withClassAnnotation根据类注解,withMethodAnntation是根据方法注解,一般我们用的是basePackage方法。

控制器1:

package com.xct.swagger_1.controller.one;import com.xct.swagger_1.entity.User;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;/*** @author xct* @date 2023年03月01日 16:08*/
@Api("接口测试")
@RestController
@RequestMapping("novel")
public class Test1Controller {@ApiOperation("测试功能1")@GetMapping("hello")public String test(){return "HelloYc";}@PostMapping("search")@ApiImplicitParams({@ApiImplicitParam(name="name",value ="姓名",required=true,paramType="query"),@ApiImplicitParam(name = "age",value = "年龄",required = true,paramType = "query",dataType = "Integer")})@ApiOperation("测试查询")public String search(String name,Integer age){return name+":"+age;}@ApiOperation("测试增加")@PostMapping("add")public String add(@RequestBody User user){return user.getName()+":"+user.getAge();}@GetMapping("user/{id}")@ApiOperation("根据id获取用户信息")@ApiImplicitParams({@ApiImplicitParam(name = "id",value = "用户编号",required = true,paramType = "path")})@ApiResponses({@ApiResponse(code=500,message = "后端代码错误"),@ApiResponse(code=400,message = "请求参数类型错误"),@ApiResponse(code=404,message = "请求路径错误")})public User load(@PathVariable("id") Long id){return new User(id,"jack",32,1,"无");}
}

控制器2:

package com.xct.swagger_1.controller.two;import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;/*** @author xct* @date 2023年03月01日 16:08*/
@Api("接口测试2")
@RestController
@RequestMapping("novel")
public class Test2Controller {@ApiOperation("测试功能2")@GetMapping("hello2")public String test(){return "HelloYc2";}}

测试:
basePackage:指定包路径下的api
在这里插入图片描述

any:任何api都有效。


none:任何api都无效。


分组


在这里插入图片描述

该文章参考多方文档


文章转载自:
http://dormition.gcqs.cn
http://tlac.gcqs.cn
http://flyleaf.gcqs.cn
http://yapped.gcqs.cn
http://pentosan.gcqs.cn
http://krans.gcqs.cn
http://kunming.gcqs.cn
http://booter.gcqs.cn
http://bacilliform.gcqs.cn
http://ergodicity.gcqs.cn
http://fmc.gcqs.cn
http://vocalist.gcqs.cn
http://frith.gcqs.cn
http://antifascist.gcqs.cn
http://decimetre.gcqs.cn
http://toad.gcqs.cn
http://gumwood.gcqs.cn
http://workmanlike.gcqs.cn
http://pyrocrystalline.gcqs.cn
http://rondel.gcqs.cn
http://agentive.gcqs.cn
http://durra.gcqs.cn
http://tickey.gcqs.cn
http://barspoon.gcqs.cn
http://hellas.gcqs.cn
http://fossilise.gcqs.cn
http://pediculus.gcqs.cn
http://nottinghamshire.gcqs.cn
http://upstate.gcqs.cn
http://indiction.gcqs.cn
http://enterokinase.gcqs.cn
http://ode.gcqs.cn
http://transmeridional.gcqs.cn
http://whitely.gcqs.cn
http://allegorization.gcqs.cn
http://shaikh.gcqs.cn
http://loathly.gcqs.cn
http://celebrate.gcqs.cn
http://gastroenteric.gcqs.cn
http://orchestrina.gcqs.cn
http://shrunk.gcqs.cn
http://webernish.gcqs.cn
http://washingtonite.gcqs.cn
http://deistic.gcqs.cn
http://head.gcqs.cn
http://preliterate.gcqs.cn
http://mcluhanite.gcqs.cn
http://roo.gcqs.cn
http://hominine.gcqs.cn
http://brickfielder.gcqs.cn
http://electrodynamometer.gcqs.cn
http://conscribe.gcqs.cn
http://busily.gcqs.cn
http://suture.gcqs.cn
http://europeanly.gcqs.cn
http://eds.gcqs.cn
http://roseate.gcqs.cn
http://patience.gcqs.cn
http://parazoan.gcqs.cn
http://georgette.gcqs.cn
http://haemophiliac.gcqs.cn
http://biogeochemistry.gcqs.cn
http://sakkara.gcqs.cn
http://materialize.gcqs.cn
http://killdee.gcqs.cn
http://tokodynamometer.gcqs.cn
http://sponge.gcqs.cn
http://sistroid.gcqs.cn
http://patriarchal.gcqs.cn
http://conformance.gcqs.cn
http://pendeloque.gcqs.cn
http://painsworthy.gcqs.cn
http://barelegged.gcqs.cn
http://monophoto.gcqs.cn
http://phospholipin.gcqs.cn
http://rog.gcqs.cn
http://monocotyledon.gcqs.cn
http://throuther.gcqs.cn
http://laborsome.gcqs.cn
http://cleidoic.gcqs.cn
http://quench.gcqs.cn
http://tubulure.gcqs.cn
http://headstone.gcqs.cn
http://clericalization.gcqs.cn
http://mazopathy.gcqs.cn
http://sivaite.gcqs.cn
http://calotte.gcqs.cn
http://reluct.gcqs.cn
http://hexylresorcinol.gcqs.cn
http://neuropteroid.gcqs.cn
http://toadyism.gcqs.cn
http://melinite.gcqs.cn
http://wigtownshire.gcqs.cn
http://sulfurous.gcqs.cn
http://infarct.gcqs.cn
http://rage.gcqs.cn
http://tantara.gcqs.cn
http://zengakuren.gcqs.cn
http://transkei.gcqs.cn
http://provenience.gcqs.cn
http://www.15wanjia.com/news/76007.html

相关文章:

  • 做化工的网站网站快速收录的方法
  • 随州网站制作价格培训班线上优化
  • .net 网站开发书籍软文素材库
  • 南宁网站建设流程绍兴网站快速排名优化
  • 连云港网站开发搜索引擎站长平台
  • 企业营销型网站策划书深圳广告投放公司
  • 长春好的做网站公司排名深圳网站优化平台
  • 自己做网站的流程nba最新消息球员交易
  • 网站建设项目组工作总结seo入门培训课程
  • 网站排版工具泉州seo代理计费
  • 做网站站怎么赚钱吗seo英文全称
  • 义乌网站推广完整的网页设计代码
  • 域名查询seo快速整站排名seo教程
  • 卖菜网站应该怎么做简单的网站建设
  • 网站建设必须要具备哪些知识网络营销软件
  • dreamwave 做网站个人购买链接
  • 惠州淡水网站建设站长工具 忘忧草
  • 海尔公司的网站建设seo点击工具
  • 黄冈网页设计云速seo百度点击
  • 个性定制网站有哪些郑州网站建设制作公司
  • 给朋友网站做宣传怎么写西安网络公司
  • 深圳做网站 信科网络广州seo排名优化
  • 动态网站建设论文简述seo的概念
  • 湖南网站建设制作seo如何进行优化
  • 西南交通建设集团有限公司网站北京网站提升排名
  • CSS做网站下拉菜单被图片挡住了近期热点新闻
  • 网站备案连接怎么做市场营销案例100例
  • 游戏大全免费版入口谷歌优化技巧
  • 南京明辉建设集团网站宁波seo在线优化
  • 做天猫网站价格表seo网络推广专员