swagger2
简介:
Swagger2 是一个规范和完整的框架,用于生成、描述、调用和可视化Restful风格的web服务,现在我们使用spring boot 整合它。
作用:
insert接口
/select接口
的文档在线自动生成;
使用
访问地址swagger接口文档:
第一种: http://localhost:8080/swagger-ui.html
第二种: http://localhost:8080/doc.html
引入依赖
<!--引入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实例@Beanpublic Docket docket() {Docket docket=new Docket(DocumentationType.SWAGGER_2).apiInfo(getInfo())//设置接口文档的信息.select().apis(RequestHandlerSelectors.basePackage("com.ykq.controller")) //指定为那些路径下得到类生成接口文档.build(); return docket;} private ApiInfo getInfo(){Contact DEFAULT_CONTACT = new Contact("李东威", "http://www.ldw.com", "110@qq.com");ApiInfo DEFAULT = new ApiInfo("用户管理系统API", "该系统中的接口专门操作用户的", "v1.0", "http://www.baidu.com",DEFAULT_CONTACT, "漫动者", "http://www.jd.com", new ArrayList<VendorExtension>());return DEFAULT;} }注解驱动
@SpringBootApplication @MapperScan(basePackages = {"com.gzx.demo1.mapper"}) //swagger注解驱动 @EnableSwagger2 public class Demo1Application { public static void main(String[] args) {SpringApplication.run(Demo1Application.class, args);} }常用注解
@Api(tags=“”): 使用在接口类上,对接口类的说明
@ApiOperation(value=""):接口方法上,对接口方法的说明
@ApiImplicitParams( @ApiImplicitParam(name=“参数名”,value="参数说明",require="是否必写",dataType="数据类型") ) : 接口方法所有参数的概述
@ApiModel(value=""): 使用在实体类上,对实体类的说明
@ApiModelProperty(value=""):使用在实体类属性上,对属性的说明
整合定时器:
在指定的时间执行相应的业务代码。
场景: oss修改图片时,存在一个冗余图片。定时删除冗余图片。
比如: 下单。30分钟未支付取消订单。 比如: 新用户注册成功后,7天发送问候语。
使用
引入定时器依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-quartz</artifactId> </dependency>创建一个定时业务类
@Configuration public class MyQuartzConfig { //定时业务代码//定义定时规则@Scheduled(cron = "0/5 * * * * ?")public void show(){System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");//发生短信 或者删除oss冗余文件 或者取消订单} }开启定时器注解驱动
@SpringBootApplication @EnableScheduling public class Demo1Application { public static void main(String[] args) {SpringApplication.run(Demo1Application.class, args);} }