HTTP 请求头/响应头 Content-Type 用于向接收方说明传输资源的媒体类型。
java
/**
* 两种初始化Map常量
* 1.new HashMap
* 2.static 静态代码块
*/
static Map<String , String> contentType = new HashMap<String , String>(200){
{
put(".jpg","image/jpeg");
put(".jpeg","image/jpeg");
}
};
//通过key获取ContentType值
public static String getContentType(String ext) {
return contentType.get(ext);
}
Java 开源日志框架,以继承改善 log4j 为目的而生,是 log4j 创始人 Ceki Gülcü 的开源产品。 它声称有极佳的性能,占用空间更小,且提供其他日志系统缺失但很有用的特性。 其一大特色是,在 logback-classic 中本地(native)实现了 SLF4J API(也表示依赖 slf4j-api) 🍜
xml
<!--slf4j日志门面-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<!--logback日志实现-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
以下只针对sql语句输出的配置
ymllogging:
level:
com.ewell.medqc.rec.management.mapper: debug
🍰 🌯 Caffeine 是基于 JAVA 8 的高性能缓存库。参考 Google Guava 的API对缓存框架重写,基于LRU算法实现,支持多种缓存过期策略。 Spring Boot 1.x版本中的默认本地缓存是Guava Cache。在 Spring5 (spring boot 2.x) 后,Spring 官方放弃了 Guava Cache 作为缓存机制,而是使用性能更优秀的 Caffeine 作为默认缓存组件
xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.7.0</version>
</dependency>
在SpingBoot启动类标上@EnableCaching注解
application.yml 配置参数
yml
spring:
# 配置缓存,初始缓存容量为10,最大容量为200,过期时间(这里配置写入后过期时间为3秒)
cache:
type: caffeine
caffeine:
spec: initialCapacity=10,maximumSize=200,expireAfterWrite=3s
这个问题是由于Nginx上传默认限制大小为1mb,如果包含过多的图片就会超出,需要手动修改nginx的配置
在linux服务上找到nginx的安装位置,在安装目录下面找到conf文件,下载到本地打开编辑,找到http{}位置,修改最大body大小
http { include /etc/nginx/mime.types; default_type application/octet-stream; client_max_body_size 20M; #此处 }
修改完成后执行重启nginx命令
./nginx -s reload
项目中经常会遇到各种需要以树形结构展示的功能,如菜单树、分类树、部门树,Hutool的TreeUtil主要是用来快速构造树形结构,以及获取所有叶子节点等操作。🍉
xml
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.22</version>
</dependency>
java
/**
* 获取构造树
**/
@ApiOperation(value = "获取构造树", notes = "获取构造树")
@GetMapping(value = "/getConstructTree")
public Result<?> getConstructTree() {
List<Tree<String>> treeList = sdSchoolClassTypeDataCategoryService.constructTree();
return Result.OK(treeList);
}