Springboot整合Swagger+mybatis-plus

目录

 1.springboot整合swagger接口文档

1.1什么是swagger2

1.2 为什么需要使用swagger2的api文档

1.3如何使用swagger2

2.springboot整合mybatis-plus

2.1 mp的简介

2.2 如何使用 


 1.springboot整合swagger接口文档

1.1什么是swagger2

它就是可以api接口,它可以对你书写的接口进行说明。并以文档的形式存在。  、

1.2 为什么需要使用swagger2的api文档

Springboot整合Swagger+mybatis-plus_第1张图片

1.3如何使用swagger2

(1)引用swagger的依赖

        
        
            io.github.jianzhichun
            spring-boot-starter-swagger2
            0.0.1
        
        
        
            com.github.xiaoymin
            swagger-bootstrap-ui
            1.9.6
        

 (2)配置swagger的信息

@Configuration //表示类似于配置文件
public class SwaggerConfig {
    @Bean //加在方法上,表示把方法的返回结果交于spring容器来管理对象,docket里面封装了接口文档的信息
    public Docket docket(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("qy168")
                .apiInfo(getInfo())
                .select()
                //只为com.aaa.controller包下的类生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.aaa.controller"))
                .build();
        return docket;
    }
    private ApiInfo getInfo(){
        Contact DEFAULT_CONTACT = new Contact("于清晨","http://www/baidu.com","[email protected]");
        ApiInfo apiInfo=new ApiInfo("QY168班级","学生管理系统API文档","1.0","http://localhost:8081/doc.html",
                DEFAULT_CONTACT,"11网络科技有限公司","about:blank");
        return apiInfo;
    }
}

Springboot整合Swagger+mybatis-plus_第2张图片

(3)使用swagger的注解  

@Api:接口类的说明 加在controller类上

@ApiOperation: 接口方法的说明。 加在controller方法上

@ApiImplicitParams: 接口方法的所有参数的说明.

@ApiImplicitParam:单个参数的说明

--name: 参数名

--value: 参数的说明

--require: 是否为必须的

--dataType: 参数类型说明 int string

@ApiModel: 实体类的说明

@ApiModelProperty: 单个参数的说明

(4)启动工程并访问swagger接口文档的路径

http://ip:port/swagger-ui.html

你可能感兴趣的:(spring,boot,mybatis,java)