同一个接口有时候想要分页,有时候又想要查全部数据,用的分页方式为mybatisPlus的方式
就是把page和row,同时设置为-1,因为小于零的话,就可以查全部,这是mybatisPlus的代码设置,不能设置为空,不然会报错
在项目中发现了一个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);
}