Spring Boot 3

Springboot3

1.srpingboot 整合swagger2

1.1什么是swagger2

Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。

1.2为什么要使用swagger2

(1) 及时性 (接口变更后,能够及时准确地通知相关前后端开发人员)
(2)规范性 (并且保证接口的规范性,如接口的地址,请求方式,参数及响应格式和错误信息)
(3)一致性 (接口信息一致,不会出现因开发人员拿到的文档版本不一致,而出现分歧)
(4)可测性 (直接在接口文档上进行测试,以方便理解业务

1.3如何使用接口文档swagger2

(1)添加依赖
在这里插入图片描述
(2)创建一个配置类 : SwaggerConfig

@Configuration
@EnableSwagger2//开启swagger注解驱动
public class SwaggerConfig {

    @Bean
    public Docket docket(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("mqc")
                .apiInfo(getInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mqc.springboot4.controller"))
                .build();
        return docket;
    }

    private ApiInfo getInfo(){
        Contact DEFAULT_CONTACT = new Contact("马墨林","http://www.baidu.com","123@qq.com");
        ApiInfo apiInfo = new ApiInfo("qy163心理测试系统API","qy163心理测试系统API","1.1.0","http://www.baidu.com"
                ,DEFAULT_CONTACT,"墨木木","http://www.jd.com",new ArrayList<VendorExtension>());
        return apiInfo;
    }
}

(3)访问swagger在线文档
路径:http://ip:port/swagger-html
在这里插入图片描述
http://ip:port/doc.html在这里插入图片描述

1.4 swagger中常用的注解

注解作用
@Api表示对类的说明常用参数
@ApiOperation说明方法的用途、作用
@ApiModel表示一个返回响应数据的信息
@ApiModelProperty描述响应类的属性
@ApiIgnore忽略某个字段使之不显示在文档中

2.springboot整合定时器-quartz

2.1 https://www.pppet.net/

(1)引入quartz依赖

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

(2)配置定时器任务

public class QuarzConfig {
    @Component //交于spring容器该类对象
    public class QuarzConfig {
        @Autowired
        private StudentMapper studentMapper;
        @Scheduled(cron = "0/5 * * * * ? ")
        public void show(){
            //1.查询过期的订单
            List<Student> students = studentMapper.selectList(null);
            System.out.println(students);
            //2.删除过期的订单
        }
    }
}

(3)开启定时器注解驱动

@SpringBootApplication
@MapperScan(basePackages = "com.mqc.springboot4.mapper")
@EnableSwagger2
@EnableScheduling//开启定时器注解
public class SpringBoot4Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringBoot4Application.class, args);
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值