在项目中发现了一个bug,两个相等的Long类型使用了==来判断是否相等,但是每次都直接跳过了if,也就是说他们是不相等的。
1 .直接声明的 不管是Long 还是long -128 -127 之间使用 == 和 equlas 都是true 因为 Long包对 常用的做了缓存。如果在这个区间直接从cache 中取。所以 == 地址值也是一样的 为true
2 new 出来的 必须使用equals .虽然做了-128 -127 做了缓存,但是new出来的是新分配的内存,地址值不一样 使用== 数值即使一样也为false.
3 使用 == 不管是直接声明的,还是new出来的 ,只要一边有基本数据类型 都可以正常对比。会自动拆箱。例如:
因为下面 int和long 属于基本类型。所以 == 会将Long 拆箱成long 直接比较数值
Long e = 300L; int f = 300; Long g = 300L; long h = 300L; System.out.println("Long与int 300 equals 结果" + (e == f));//true System.out.println("Long与long 300L equals 结果" + (g == h));//true
测试代码
java
public static void main(String[] args) {
DemoLong demoLong=new DemoLong();
demoLong.setA(100L);
demoLong.setB(11237L);
DemoLongTwo demoLongTwo=new DemoLongTwo();
demoLongTwo.setAa(100L);
demoLongTwo.setBb(11237L);
System.out.println(demoLong.getA()== demoLongTwo.getAa());
System.out.println(demoLong.getB()== demoLongTwo.getBb());
System.out.println(demoLong.getA().equals( demoLongTwo.getAa()));
System.out.println(demoLong.getB().equals(demoLongTwo.getBb()) );
}
结果

业务需求除excel文件下载还要需要实现dbf文件格式的下载,之前的excel是根据easyexcel无对象实现解析数据库视图,实现动态的读取视图字段和内容,现在这个dbf下载则就是在上次的基础上修改实现的,上次的案例在这边🏝️
xml <!-- 读写dbf文件-->
<dependency>
<groupId>com.github.albfernandez</groupId>
<artifactId>javadbf</artifactId>
<version>1.11.2</version>
</dependency>
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