springboot集成swagger2,超级简单

1,导入依赖

<!--swagger-->
        <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专用的配置类,也可以自己在applicant里配置】

直接在applicant里配置

/**
     * swagger配置
     * localhost:8080/v2/api-docs
     * localhost:8080/swagger-ui.html
     *
     * @return
     */
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2构建RESTful APIs,献给伟大的程序员")
                .description("纯棉生活小程序api")
                .termsOfServiceUrl("www.baidu.com")
                .version("1.0").build();
    }

3,开始使用吧,写一个controller

@Api(description = "【用户接口】登录,修改个人信息")
@RestController
public class LoginController extends BaseController {

    @ApiOperation(value = "用户登录")
    @RequestMapping(value = "/login", method = {RequestMethod.POST, RequestMethod.GET})
    public ResultSet userLogin(HttpServletRequest request,
                               @ApiParam(name = "mobile", value = "手机号码", required = true) @RequestParam String mobile,
                               @ApiParam(name = "code", value = "验证码", required = true) @RequestParam String code
    ) {

        return ResultSet.createSuccess("登录成功!");
    }


}

好了

看一下运行的样子吧   【http://localhost:9090/swagger-ui.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值