# SpringBoot学习
**Repository Path**: lt199934/spring-boot-learning
## Basic Information
- **Project Name**: SpringBoot学习
- **Description**: SpringBoot的学习仓库
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2022-03-01
- **Last Updated**: 2022-05-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# springboot的学习笔记
## 一、什么是springboot
约定大于配置是springboot的核心用来简化配置的一个框架
Spring Boot 将日常企业应用研发中的各种场景都抽取出来,做成一个个的 starter(启动器),starter 中整合了该场景下各种可能用到的依赖,用户只需要在 Maven 中引入 starter 依赖,SpringBoot 就能自动扫描到要加载的信息并启动相应的默认配置。starter 提供了大量的自动配置,让用户摆脱了处理各种依赖和配置的困扰。所有这些 starter 都遵循着约定成俗的默认配置,并允许用户调整这些配置,即遵循“约定大于配置”的原则。
## 二、Swagger
是一个动态生成接口文档的一个框架,用于和前端或测试岗位的同事进行对接。
```xml
io.springfox
springfox-swagger2
2.9.2
io.springfox
springfox-swagger-ui
2.9.2
```
```java
package com.xxgc.helloworld.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.w3c.dom.DocumentType;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
//是否开启前端ui显示 生产环境调为false
.enable(true)
.select()
//扫描有哪些接口(controller)要生成文档
.apis(RequestHandlerSelectors.basePackage("com.xxgc.helloworld.controller"))
//接口中所有路径都扫描
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
//api文档标题
.title("HelloWorld工程")
//文档描述
.description("工程文档描述")
//服务条款url
.termsOfServiceUrl("https://www.baidu.com")
//版本号
.version("1.0.0")
.build();
}
}
```
## 三、springboot热部署
pom.xml
```xml
org.springframework.boot
spring-boot-devtools
true
true
```
application.yml
```yml
spring:
devtools:
restart:
enabled: true #开启热部署
additional-paths: src/main/java #重启的目录
```
## 四、JWT
JSON Web Token(JWT)是一种开放标准,用于作为Web应用中的令牌,用于在各方之间安全地将信息作为JSON对象传输。在数据传输中完成数据加密、签名等相关处理。
**实现前后端分离就用JWT**
Jwt的核心是什么:一种信息交换,一种是用来做javaweb中的安全验证
### 流程
1. 用户使用用户名密码请求服务器
2. 服务器验证用户信息
3. 服务器通过验证发送给用户一个token
4. 客户端存储token,并每次请求时附带一个token值
5. 服务器验证token并返回数据
## 五、Quartz 框架(石英)
### cron表达式
3,6,9,12每月1号 6点检查数据库
秒 分钟 小时 日 月 星期 年
0 0 6 1 3,6,9,12 ? *
例子
每个月5号9点执行
0 0 9 5 * ? *
## 六、Redis