swagger2就是个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的
添加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.7.8</version>
</dependency>
需要一个配置类
@Configuration
@EnableSwagger2 //开启swagger注解驱动
public class SwaggerConfig {
@Bean //把方法返回的数据对象 交于spring容器管理
public Docket docket(){
Docket docket = new Docket(DocumentationType.SWAGGER_2).groupName("liu222")
.apiInfo(getInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.liu.controller")) //只为com.ykq.controller包下的类生成接口文档
.build();
return docket;
}
private ApiInfo getInfo(){
Contact DEFAULT_CONTACT = new Contact("ming", "http://www.baidu.com", "32099885@qq.com");
ApiInfo apiInfo=new ApiInfo("管我什么", "描述一下", "1.1.0", "http://www.jd.com",
DEFAULT_CONTACT, "串串", "http://www.百度.com", new ArrayList<VendorExtension>());
return apiInfo;
}
}
> 使用swagger注解对接口参数加以说明。
> @Api(tags="")====使用在controller类上
@RestController
@RequestMapping("student")
@Api(tags = "学生操作")
public class StudentController {
> @ApiOperation(value="")====接口方法上 接口方法加以说明
@PostMapping("list/{page}/{size}")
@ApiOperation(value = "根据条件分页查询学生信息")
public Result list(
@ApiParam(value = "当前页面",name ="page",required = true,defaultValue = "1")
@PathVariable Integer page,
@ApiParam(value = "每页条数",name ="size",required = true,defaultValue = "3")
@PathVariable Integer size,
@RequestBody StudentVo studentvo
> @ApiModel====实体类
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "学生实体类")
public class Student implements Serializable {
/**
> @ApiModelProperty===>实体类的属性说明
@ApiModelProperty(value = "学生编号")
@TableId("sid")
private Integer sid;
定时器-quartz
定时器: 在指定的时间执行相应的业务代码。
引入quartz依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
使用
@Component //交于spring容器该类对象
public class hh {
@Autowired
private studentMapper studentMapper;
@Scheduled(cron = "0/5 * * * * ? ")
public void show(){
List<Student> student = studentMapper.selectList(null);
System.out.println(student);
}
}
在Application加上 开启定时器注解
@SpringBootApplication
@MapperScan(basePackages = "com.liu.mapper")
@EnableScheduling //开启定时器注解
public class Springboot05Application {
public static void main(String[] args) {
SpringApplication.run(Springboot05Application.class, args);
}
}