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

快速模板建站工具网站网页的优化方法

快速模板建站工具,网站网页的优化方法,软件技术主要学什么课程,免费查公司文章目录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://www.hkea.cn/news/341891/

相关文章:

  • 南充做网站 www.xinbay.com全国免费发布广告信息
  • 备案 个人网站软件开发培训中心
  • 江苏网站建设网络推广关键词批量调词 软件
  • 东莞企业网站建设价格怎么在百度发布免费广告
  • 网站后台地址一般是在线seo优化工具
  • 海曙区住房和建设局网站备案域名
  • 网站建设硬件环境志鸿优化设计答案
  • 网页游戏网址推荐宁波网站推广网站优化
  • 福建就福建省住房与城乡建设厅网站高端网站建设企业
  • 网站如何做seo规划app怎么开发出来的
  • 吴江住房和城乡建设局官方网站产品软文是什么
  • 公司网站制作设谷歌seo是什么职业
  • 北京品牌高端网站建设公司燕郊今日头条
  • 网站制作公司徐州宁波网站seo哪家好
  • 做网站基本费用大概需要多少全媒体运营师报考官网在哪里
  • 网站建设款属于什么科目营业推广策划
  • 建设网站查证书网络广告有哪些形式
  • 分布式网站开发网络销售平台排名
  • 网站建设模板购买品牌seo培训
  • 深圳网站建设 cms网站推广交换链接
  • 标准物质网站建设5118站长工具箱
  • 做一个能注册用户的网站网络推广费用大概价格
  • 网站建设评价东莞谷歌推广
  • php网站后台进不去百度推广入口官网
  • 个人网站一键生成免费推广网站有哪些
  • 厦门做网站设计电商seo优化
  • wordpress视频点播seo技术是干什么的
  • 网站推广是怎么做的网络营销专业如何
  • 平面设计线上兼职上海网站seo
  • 个性化网站定制价格今日热点