springboot整合swagger2和定时器

swagge2

什么是swagge

swagger2可以在线生成接口文档而且可以对接口进行测试

引入依赖

<!--引入swagger2依赖-->
        <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>swagger-spring-boot-starter</artifactId>
            <version>1.9.1.RELEASE</version>
        </dependency>
        <!--图形化依赖-->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>swagger-bootstrap-ui</artifactId>
            <version>1.9.6</version>
        </dependency>

创建配置类

@Configuration
public class SwaggerConfig {
    //创建swagger实例
    @Bean
    public Docket docket() {
        Docket docket=
             new Docket(DocumentationType.SWAGGER_2)
                 .apiInfo(getInfo())	//设置接口文档的信息
                 .select()
                 .apis(RequestHandlerSelectors.basePackage("com.gym.controller"))	//为指定路径下的类生成接口文档
                 .build();
        return docket;
    }

    private ApiInfo getInfo(){
        Contact DEFAULT_CONTACT = new Contact("作者", "网址", "邮箱");
        ApiInfo DEFAULT = new ApiInfo("接口名", "该接口作用", "版本", "http://www.baidu.com",
                DEFAULT_CONTACT, "单位名", "http://www.jd.com", new ArrayList<VendorExtension>());
        return DEFAULT;
    }
}

开启swagger注解驱动

@EnableSwagger2	//开启注解驱动
public class 主类Application{
    public static void main(String[] args){}
}

swagger2常用注解

1. @Api(tags="")	//使用在接口类上,对接口类的说明
2. @ApiOperation(value="")	//使用在接口方法上,对接口方法的说明
3. @ApiImplicitParams(	//对接口方法所有参数的概述
           @ApiImplicitParam(name="参数名",value="参数说明",require="是否必填",dataType="数据类型") 
    )
4. @ApiModel(value="")	//使用在实体类上,对实体类的说明
5. @ApiModelProperty(value="")	//使用在实体类属性上,对属性的说明

文档访问方式

第一种: http://localhost:8080/swagger-ui.html

第二种: http://localhost:8080/doc.html

定时器

什么是定时器

在指定时间执行的相应业务代码

引入依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>

创建定时业务类

@Configuration
public class QuartzConfig {
    @Scheduled(cron = "0/5 * * * * ?")	//cron规则
    public void show(){
        //规则达成后执行的业务代码
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    }
}

开启定时器注解驱动

@EnableScheduling	//开启注解驱动
public class 主类Application{
    public static void main(String[] args){}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值