swagger界面非必传参数的设置

修改之前:

第一次代码实现:
@RequestMapping(path="/getByStoreAndTypeAndSn/{storeId}/{versionType}/{terminalSn}", method=RequestMethod.GET )
public TerminalSet getListByStoreIdAndVersionAndSn(@PathVariable("storeId") Long storeId,@PathVariable("versionType") Integer versionType,@PathVariable("terminalSn") String terminalSn){
   
    return terminalSetService.getListByStoreIdAndVersionAndSn(storeId,versionType,terminalSn);
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Swagger 是一种用于设计、构建、文档化和使用 RESTful Web 服务的工具。它使用 OpenAPI 规范来定义 RESTful API 的接口,可以通过 Swagger UI 界面来测试和调试 API 接口。Swagger 通过注解方式来生成 API 文档,因此可以很方便地与 Spring Boot 等框架集成。 下面是在 Spring Boot 中使用 Swagger 的示例: 1. 在 pom.xml 文件中添加 Swagger 的依赖: ```xml <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> ``` 2. 创建一个 Swagger 配置类,用于配置 Swagger 的相关参数: ```java @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.example.controller")) .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("API 文档") .description("这是一个 Swagger API 文档") .version("1.0") .build(); } } ``` 在上面的代码中,使用 @EnableSwagger2 注解启用 Swagger,创建一个 Docket 实例用于配置 Swagger 的相关参数,其中: - `apis(RequestHandlerSelectors.basePackage("com.example.controller"))` 指定要扫描的 API 接口所在的包; - `paths(PathSelectors.any())` 指定要扫描的 API 接口的 URL 路径; - `apiInfo()` 用于设置 API 文档的标题、描述和版本等信息。 3. 在 Controller 中使用 Swagger 的注解来生成 API 文档: ```java @RestController @RequestMapping("/user") @Api(tags = "用户管理") public class UserController { @GetMapping("/{id}") @ApiOperation(value = "根据 ID 获取用户信息", notes = "根据用户 ID 获取用户信息") public User getUserById(@PathVariable("id") Integer id) { ... } @PostMapping("/") @ApiOperation(value = "添加用户", notes = "添加用户") public void addUser(@RequestBody User user) { ... } @PutMapping("/{id}") @ApiOperation(value = "更新用户信息", notes = "根据用户 ID 更新用户信息") public void updateUser(@PathVariable("id") Integer id, @RequestBody User user) { ... } @DeleteMapping("/{id}") @ApiOperation(value = "删除用户", notes = "根据用户 ID 删除用户") public void deleteUser(@PathVariable("id") Integer id) { ... } } ``` 在上面的代码中,使用 @Api 注解来指定 API 接口的标签,使用 @ApiOperation 注解来指定 API 接口的名称、描述和参数说明等。 4. 在启动类中添加 @EnableSwagger2 注解来启用 Swagger: ```java @SpringBootApplication @EnableSwagger2 public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 启动应用程序后,在浏览器中访问 http://localhost:8080/swagger-ui.html 即可查看生成的 API 文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值