Springboot 整合Swagger 2框架 让接口查看及调试更加优雅

本文介绍了如何在Springboot项目中整合Swagger2框架,详细展示了配置步骤和Controller注解的使用,使得接口查看和调试变得更加便捷。通过创建ApiInfo和启用Swagger,实现了接口文档的自动生成,并提供了在线调试功能。
摘要由CSDN通过智能技术生成

//不需要时,或者生产环境可以在此处关闭

.enable(true);

}

private ApiInfo apiInfo() {

return new ApiInfoBuilder()

.title("JCccc springboot整合Swagger2项目 ")

.description(“描述:测试使用Swagger2!”)

//服务条款网址

.termsOfServiceUrl(“https://blog.csdn.net/qq_35387940”)

.contact(“JCccc”)

.version(“1.0”)

.build();

}

}

然后是写一个Controller ,整合Swagger2框架注解 Swagger2TestController.java:

import com.alibaba.fastjson.JSONObject;

import com.soelegant.elegantdemo.pojo.UserInfo;

import io.swagger.annotations.Api;

import io.swagger.annotations.ApiImplicitParam;

import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

/**

  • @Author:JCccc

  • @Description:

  • @Date: created in 20:54 2019/5/25

*/

@Api(value = “测试各种方法”, tags = {“测试使用Controller”})

@RestController

public class Swagger2TestController {

@ApiOperation(value = “测试Swagger2接口”, notes = “传入编号!”)

@ApiImplicitParam(name = “id”, value = “id”, required = true)

@RequestMapping(value = “/swaTest2/{id}”, method = RequestMethod.GET)

public String TestSwa2(@PathVariable(“id”) Integer id) {

  • 9
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值