栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

常用常忘常记

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

常用常忘常记

mysql

   

# 添加字段和备注
    ALTER TABLE t_corp_realname_info ADD manufacture_id varchar(20) NULL COMMENT '制造商ID' AFTER developer_id;
# 查询最新两条数据
    order by update_time DESC limit 2;
# 创建六位递增数据
    select CONCAt("R", LPAd((@i:=@i+1), 6, 0)) manufacture_id, t.* from t_user t,(select @i:=0) init where t.user_id is not null;
    select LPAd((@i:=@i+1), 6, 0) manufacture_id, t.* from t_user t,(select @i:=0) init where t.user_id is not null;

    注意点:
        1.查询的时候需要考虑状态和标志位
        

stream
    
    去重
        .stream().collect(collectingAndThen(toCollection(()
            -> new TreeSet<>(comparing(ManufactureIdPo::getIdentificationNumber))), ArrayList::new));


    list合并去重
        List collect = Stream.of(listA, listB).flatMap(Collection::stream).distinct().collect(Collectors.toList());
    
    
浅拷贝和深拷贝
    https://demon.blog.csdn.net/article/details/54572908
    首先注意几个点,对象类型分基本数据类型、和引用类型
    String是不可变的,引用类型浅拷贝内存地址都是相同的(hashCode相同),深拷贝相当于重新写入了一个新的内存地址(hashCode不相同)
    
    浅拷贝
        对象拷贝
            BeanUtils.copyProperties(source, target);
        拷贝list
            ArrayList targetList = new ArrayList<>();
            Collections.addAll(repeatList, new ManufactureIdPo[sourceList.size()]);
            Collections.copy(targetList, sourceList);
            
            new ArrayList<>(sourceList)
            
            targetList = new ArrayList<>();
            targetList.addAll(sourceList);
            
            浅拷贝因为是新new出来的一个list,所以add(),delete()不会影响上一个list


    深拷贝
        在Java语言中,如果需要实现深克隆,可以通过覆盖Object类的clone()方法实现,也可以通过序列化(Serialization)等方式来实现。
        (如果引用类型里面还包含很多引用类型,或者内层引用类型的类里面又包含引用类型,使用clone方法就会很麻烦。这时我们可以用序列化的方式来实现对象的深克隆。)
        

实现六位数递增代码
    

private String getNewMFGId() {
        String newMFGId;
        String maxMFGIdNum = corpRealNameMapper.getMaxMFGIdNum();
        // 如果能查询出数据,则再原有数据上+1
        if (StringUtils.isNotEmpty(maxMFGIdNum)) {
            int no = Integer.parseInt(maxMFGIdNum);
            int newMFGIdNo = ++no;
            newMFGId = String.format("%06d", newMFGIdNo);
        } else {
            newMFGId = "000001";
        }
        return newMFGId;
    }


redis
    

redisTemplate.opsForValue().set("key", value); // 这样设置的是没有过期时间的
Objects.equals(redisTemplate.hasKey(redisKey), Boolean.TRUE) // 用于判断redis中key是否存在
Long leftTime = redisTemplate.getExpire(redisKey); // 获取过期时间

    
    

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/891723.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号