欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

swagger应用配置类

程序员文章站 2022-03-15 12:36:06
...

swagger应用配置类

package com.user.swaggerconfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com"))
                .paths(PathSelectors.any())
                .build();
    }

    private  ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("swaggerconfig")
                .description("更多详情访问我的github:https://github.com/wangnian666/")
                .termsOfServiceUrl("https://github.com/wangnian666/")
                .contact("liangxu")
                .version("1.0")
                .build();
    }
}

在接口上的应用

   @ResponseBody
    @RequestMapping(value = "judgePAP",method = RequestMethod.POST)
    @ApiOperation(value = "判断用户输入的手机号是否已经被注册过",notes = "查询数据库",response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",required = false,name = "phone",value = "手机号"),
            @ApiImplicitParam(paramType = "query",required = false,name = "pwd1",value = "密码一"),
            @ApiImplicitParam(paramType = "query",required = false,name = "pwd2",value = "密码二")
    })
    public String JudgePhoneAndPwd(@RequestParam("phone")String phone,@RequestParam("pwd1")String pwd1,@RequestParam("pwd2")String pwd2,Model mo){
        Jedis jedis = new Jedis("148.70.68.230",6379);
        jedis.get("phone");
        mo.addAttribute("phone",jedis.get("phone"));
        return tus.judgePhoneAndPwd(phone,pwd1,pwd2/*,request*/);
    }
相关标签: demo